Hi, how do I index the “code” and “pop” fields in the documents like the following in Atlas? Note that the field under the “cities” is dynamic and can be any city in the world. Thanks.
The Atlas search UI and API allow you to use a “dynamic” mapping when the index is created.
So you can map dynamically anything below “cities”…
Now the problem is that the names you mentioned are field names and not values. This is not being indexed for text searching, perhaps you should use a model like this:
We cannot change the model as our customers have been using the model for quite a long time. The problem with using dynamic mapping is that we have a lot of fields under each city and we only want to index a few of them. Also, there are fields under each city that are nested documents and we want to index some of the fields in those nested documents as well.
I tried to simplify the document so that it is easier to communicate; however, it seems that it actually led to more confusion.
The example at the bottom is a more realistic snippet of our documents. The fields like “CUSTOMER_ID” and “CONTACT_ID” in the example are dynamically extracted from the customer’s data, which is unknown to us. If I search for documents that meet the following criteria, I would expect the sample document to return.
term_display_name: customer_id
name (of data class): Customer Number
column_type: string
The sample document is also expected to return with the following criteria:
You can use a wild card path to force that each of the terms will be looked at a field with a specific name using the following “regex” as the path"*.<FIELD_NAME>":
See how the query using compound to form 3 different compound conditions and using *.type , *.name and *. term_display_name to only hit specific nested fields.
In this case my search index was completely dynamic mapping. But if you know that only specific field paths are dynamically queried then only map those with dynamic toggle/flag.