0

I have been trying to use to the bulk insert function but every time I use it is showing some mapping error . Has the bulk insert function declaration have changed from nest 1.x to nest 5.x because in 5.x nest documentation I did not find the .bulk() function . Please Suggest

Code for bulk insert:

        public void bulkInsert(List<BaseData> recordList, List<String> listOfIndexName)
    {

          BulkDescriptor descriptor = new BulkDescriptor();
            descriptor.Index<BaseData>(op => op
                .Document(recordList[j])
                .Index(listOfIndexName[j])

               );


        }

        var result = clientConnection.Bulk(descriptor);


    }

My list of data that I am passing looks something like this :

[ElasticsearchType(IdProperty = "number")]


class TicketData : BaseData
{        
    //[ElasticProperty(Index = FieldIndexOption.NotAnalyzed, Store = true)]


    [Date(Name = "sys_updated_on", Store = true)]
    public DateTimeOffset sys_updated_on { get; set; }


      [Text(Name = "number", Store = true)] 
    public override string  number { get; set; }


   [Text(Name = "incident_state", Store = true)]
    public string incident_state { get; set; }


  [Text(Name = "location", Store = true)]
    public string location { get; set; }


   [Text(Name = "assigned_to", Store = true)]
    public string assigned_to { get; set; }



[Text(Name = "u_knowledge_id", Store = true)]
    public string u_knowledge_id { get; set; }


    [Text(Name = "u_knowledge_id.u_process_role", Store = true)]
    public string u_knowledge_id_u_process_role { get; set; }

}

5
  • And the error is? Commented Apr 20, 2017 at 6:14
  • This solution might help you. stackoverflow.com/questions/22017858/… Or you can refer to this, from this link you can get more basic idea about bulk insert thank you! Commented Apr 20, 2017 at 6:18
  • you look like you're missing code in your example e.g. what is descriptor? could you edit your question to add that detail please. Also, what is the mapping error? what error does Elasticsearch return? what does the bulk request json look like? Commented Apr 20, 2017 at 6:32
  • I have added the descriptor Russ. Still the error is the same Commented Apr 20, 2017 at 7:36
  • The error is something like this [0] {index returned 400 _index: datd.ticketlog01-2017.15 _type: basedata _id: IN1 _version: 0 error: Type: illegal_argument_exception Reason: "Can't merge a non object mapping [u_knowledge_id] with an object mapping [u_knowledge_id]" CausedBy: ""} Nest.BulkResponseItemBase {Nest.BulkIndexResponseItem} Commented Apr 20, 2017 at 7:36

1 Answer 1

2

It seems that NEST cannot infer the correct type of your entity because you specify generic type BaseData whereas the actual type is TicketData. You should specify the actual type of entity you want to index. Since you may have different types inside your list, you can get the actual type using GetType() method:

descriptor.Index<BaseData>(op => op
    .Document(recordList[j])
    .Index(listOfIndexName[j])
    .Type(recordList[j].GetType())
);

Currently your query tries to dynamically create a different type with default mapping instead of interpreting it as existing type with explicit mapping

Sign up to request clarification or add additional context in comments.

2 Comments

The error isDebugInformation "Invalid NEST response built from a successful low level call on POST: /_bulk\r\n# Invalid Bulk items:\r\n operation[0]: index returned 400 _index: datd.ticketlog01-2017.15 _type: ticketdata _id: IN1 _version: 0 error: Type: illegal_argument_exception Reason: \"Can't merge a non object mapping [u_knowledge_id] with an object mapping [u_knowledge_id]\" CausedBy: \"\"\r\n operation[1]: index returned 400 _index: datd.ticketlog01-2016.30 _type: ticketdata
Looks like a field type conflict with other object type. What other mappings do you have?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.