Omar Himada
Omar Himada

Reputation: 2588

Can't use string as a value for _id in Elasticsearch

Heyo,
We have a document object with property Id (that we know auto maps to the _id field) and we can get it to work as an int and a System.Guid.

However when we change it to a string, which would better fit our use case, we get the following exception when trying to index:

mapper_parsing_exception Reason: failed to parse [id] CausedBy: Type: illegal_argument_exception Reason: For input string: "R700"

Not really sure what to try here. We want to have a string _id and according to online resources we should be able to, however we get this exception. Any help much appreciated!

EDIT: we are inferring the Id from a property named Id on the POCO, I should have clarified. Example:

public class MyDocument {
    public string Id { get; set; }
    ...
}

Upvotes: 1

Views: 779

Answers (2)

v.karbovnichy
v.karbovnichy

Reputation: 3314

Another option will be to create proper mappings for all your fields so auto-inference will be disabled.

Upvotes: 1

Aaron M. Eshbach
Aaron M. Eshbach

Reputation: 6510

If you have already created the index with an int or a guid as the Id field, you will need to recreate the index with the new POCO that has the string as the Id field before you can store that type in the index.

Upvotes: 3

Related Questions