question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mapping error illegal_argument_exception

See original GitHub issue

I have this mapping error message on some operations. In a particular controller, it happens on delete. It wants to map some text field to boolean and fails.

Elasticsearch.Net.ElasticsearchClientException: Request failed to execute. ServerError: Type: illegal_argument_exception Reason: "mapper [entityFrameworkEvent.entries.changes.newValue] of different type, current_type [text], merged_type [boolean]" at Audit.Elasticsearch.Providers.ElasticsearchDataProvider.InsertEventAsync(AuditEvent auditEvent) at Audit.Core.AuditScope.SaveEventAsync(Boolean forceInsert) at Audit.Core.AuditScope.SaveAsync() at Audit.EntityFramework.DbContextHelper.SaveScopeAsync(IAuditDbContext context, AuditScope scope, EntityFrameworkEvent event) at Audit.EntityFramework.DbContextHelper.SaveChangesAsync(IAuditDbContext context, Func1 baseSaveChanges) at Audit.EntityFramework.AuditDbContext.SaveChangesAsync(CancellationToken cancellationToken) at MyApi.Controllers.ClinicianController.DeleteClinicianAsync(Int32 clinicianId) in C:\dev\appbackend\src\MyApi\Controllers\ClinicianController.cs:line 186 at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at System.Threading.Tasks.ValueTask1.get_Result() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync() at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIIndexMiddleware.Invoke(HttpContext httpContext) at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

But it logs perfectly on an insert operation in this same controller.

Version used

  • Audit.EntityFramework.Core: 12.3.5
  • Audit.Net.Elasticsearch: 12.3.5
  • Elasticsearch docker image: docker.elastic.co/elasticsearch/elasticsearch:6.3.1

API referencing Audit components is in a docker container while elasticsearch is on another one.

It used to work well with older version of the elasticsearch image (6.2.4) and Audit components version 12.1.11.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
thepirat000commented, Aug 23, 2018

There is another way you can avoid this problem from client-side, and is making sure all the object properties of the audit event are serialized in the same way, for example as a JSON string.

For the EF event you could override the values in a custom action as follows:

Audit.Core.Configuration.AddCustomAction(ActionType.OnEventSaving, scope =>
{
    foreach(var entry in scope.Event.GetEntityFrameworkEvent().Entries)
    {
        // Fix "Entity" property
        entry.Entity = ToJson(entry.Entity);
        // Fix Changes properties
        if (entry.Changes != null)
        {
            foreach (var change in entry.Changes)
            {
                change.NewValue = ToJson(change.NewValue);
                change.OriginalValue = ToJson(change.OriginalValue);
            }
        }
        // Fix ColumnValues properties
        if (entry.ColumnValues != null)
        {
            foreach (var colKey in entry.ColumnValues.Keys.ToList())
            {
                entry.ColumnValues[colKey] = ToJson(entry.ColumnValues[colKey]);
            }
        }
        // Fix Primary Key properties
        if (entry.PrimaryKey != null)
        {
            foreach (var pkKey in entry.PrimaryKey.Keys.ToList())
            {
                entry.PrimaryKey[pkKey] = ToJson(entry.PrimaryKey[pkKey]);
            }
        }
    }
});

private static string ToJson(object obj)
{
    return obj == null ? null : JsonConvert.SerializeObject(obj, Audit.Core.Configuration.JsonSettings);
}

So you end up having records like:

image

0reactions
xavieracostapolocommented, Jul 22, 2020

There is another way you can avoid this problem from client-side, and is making sure all the object properties of the audit event are serialized in the same way, for example as a JSON string.

For the EF event you could override the values in a custom action as follows:

Audit.Core.Configuration.AddCustomAction(ActionType.OnEventSaving, scope =>
{
    foreach(var entry in scope.Event.GetEntityFrameworkEvent().Entries)
    {
        // Fix "Entity" property
        entry.Entity = ToJson(entry.Entity);
        // Fix Changes properties
        if (entry.Changes != null)
        {
            foreach (var change in entry.Changes)
            {
                change.NewValue = ToJson(change.NewValue);
                change.OriginalValue = ToJson(change.OriginalValue);
            }
        }
        // Fix ColumnValues properties
        if (entry.ColumnValues != null)
        {
            foreach (var colKey in entry.ColumnValues.Keys.ToList())
            {
                entry.ColumnValues[colKey] = ToJson(entry.ColumnValues[colKey]);
            }
        }
        // Fix Primary Key properties
        if (entry.PrimaryKey != null)
        {
            foreach (var pkKey in entry.PrimaryKey.Keys.ToList())
            {
                entry.PrimaryKey[pkKey] = ToJson(entry.PrimaryKey[pkKey]);
            }
        }
    }
});

private static string ToJson(object obj)
{
    return obj == null ? null : JsonConvert.SerializeObject(obj, Audit.Core.Configuration.JsonSettings);
}

So you end up having records like:

image

Este misma solucion me toco aplicar al momento de integrar EntityFramework con ElasticSearch, al momento de actualizar pasaba lo mismo, tengo mis dudas con el rendimiento de esto.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - Why am I getting an IllegalArgumentException when ...
The immutable static factories for Map and Set do not allow duplicates (a map entry is ... If I add them one by...
Read more >
java.lang.IllegalArgumentException: no mapping found for ...
​This issue occurs if Elasticsearch configuration is not done properly either in cmxserver.properties or cmxcleanse.properties.. The Elasticsearch path is not ...
Read more >
[ERROR] java.lang.IllegalArgumentException: Mapping for xxx ...
​This issue occurs because of the wrong delimiter while importing the data, which corrupted the metadata in the PowerCenter designer. The issue happens...
Read more >
IllegalArgumentException with java.util.Map after ...
First subset entries in Map greater than second (i.e two fields then one). But Exception does not throws on bean without setters and...
Read more >
"Invalid <url-pattern> * in filter mapping" error when ...
When deploying Inspector in Tomcat, the following error is observed in the Catalina ... IllegalArgumentException: Invalid * in filter mapping .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found