0

I currently have an index in Elasticsearch 5.5 that has several different document types in it. One of the documents is a complex POCO object that I'm indexing to Elasticsearch using dynamic mapping (no mapping set up in advance). The other document types in the same index do have mapping. I've needed to add the routing required flag to the index, which is fine for the documents that have mapping I just use:

  .Mappings(m => m
   .Map<DocType>(mDocType => mDocType.Properties(DocType.AddAllMappings).RoutingField(routing => routing.Required()))

Is there anyway of me adding the RoutingField required setting to the document that is being dynamically mapped? I'd rather not have to set up all the mapping, child elements etc. for this document because as I mentioned it's a complex object.

1 Answer 1

0

See the 3rd example in the index mapping api for an example to add a specific field to a type mapping.

Each distinct document type has its own mapping and (to my knowledge, haven't worked with 5.x in a while) by default the mapping will dynamically add new fields in the mapping. this behavior stays the same unless you turn if off. When using the mapping api, you basically append some proprieties to the exisintg mapping (the one created dynamically by ES) so i believe you can simply use that api, add your field to your data without declaring the whole thing again or having trouble adding new fields dynamically to it in the future.

Actually, you could just add the field in the data directly without having to care about the mapping at all.

On a side note, you can get the current mapping of your type with a GET on the index mapping; which is a correctly formatted mapping of your current dynamic mapping (so you don't need to rewrite all of it yourself, if you end up wanting to add a field and make it static or something; you might also want to back that up if you're playing around with mappings).

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

2 Comments

Thanks @littledaxter. I have the issue though where I can't even add the dynamic document to the cluster to begin with as it's requesting the routing field is required after I set up the mapping for the other document types. So in my case mDocType is initially mapped and includes the routing required flag. Then any other unmapped documents through an error when I try to add them to the cluster.
Regarding the GET on existing index mapping, I was able to run that but getting a JSON of the mapping whereas I'm implementing NEST to create the document mapping. Looking into how I can use that

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.