Specify a child mapping for attribute with variable name


#1

I have a document such as the following and I want to map the child fields “name” and “displayValue” in the full text index. I’ve created a child mapping for “tags”, but how to handle the next level, as the property name is unknown?

{
   "tags": {
       "125J": {
           "displayValue": "food",
           "name": "tag_food"
       },
      "1s7Y": {
           "displayValue": "New Years Day",
           "name": "tag_nyd"
      }
   }
   "content": "content for a document that mentions food"
}

#2

I have the same question. It works if “dynamic” is set for “tags”, but then everything is indexed, not possible to limit to some fields. In this example, how would it be possible to index only “name”, but not “displayValue” to keep the index as small as possible?

And a similar question, if I have a JSON like this:

    {"tags": [
     {"type" : "foo",
       "title": "this is a title we want in the index"
     },
     {"type: "bar",
       "title": "this title we don't want to index"
     }
  ]
}

Is it possible to index only the elements in type “foo”, but not in type “bar”?


#3

Apologies on the late response.

I’ve created a child mapping for “tags”, but how to handle the next level, as the property name is unknown?

A type mapping needs the exact field name, so to achieve this, I’d remodel the data to this:

{
  "tags": [
    {
      "id": "125J",
      "displayValue": "food",
      "name": "tag_food"
    },
    {
      "id": "1s7Y",
      "displayValue": "New Years Day",
      "name": "tag_nyd"
    }
  ],
  "content": "content for a document that mentions food"
}

… and then set up the type mappings to tags.Name with “only index specific fields” selected.

In this example, how would it be possible to index only “name”, but not “displayValue” to keep the index as small as possible?

Select “only index specific fields”.

Is it possible to index only the elements in type “foo”, but not in type “bar”?

In FTS the unit of a match is the document. So, while it can search within the contents of an array, if it finds something, the entire document is considered a match. So “type” has to be a top level field if you want to display documents of a certain type only. That said you will still be able to print all documents that contain “foo” by creating the type mapping: tags.type