0

I can't seem to get nested objects to highlight when using an _all search.

My index:

{
   "settings":{
      "analysis":{
         "analyzer":{
            "nGramAnalyzer":{
               "type":"custom",
               "filter":[
                  "lowercase",
                  "asciifolding",
                  "NGramFilter"
               ],
               "tokenizer":"WhitespaceTokenizer"
            },
            "WhitespaceAnalyzer":{
               "type":"custom",
               "filter":[
                  "lowercase",
                  "asciifolding"
               ],
               "tokenizer":"WhitespaceTokenizer"
            },
         },
         "filter":{
            "NGramFilter":{
               "type":"ngram",
               "min_gram":1,
               "max_gram":20
            }
         },
         "tokenizer":{
            "WhitespaceTokenizer":{
               "type":"whitespace"
            }
         }
      }
   },
   "mappings":{
      "CustomerSearchResult":{
         "_all":{
            "analyzer":"nGramAnalyzer",
            "search_analyzer":"WhitespaceAnalyzer"
         },
         "properties":{
            "customerId":{
               "type":"string",
               "index":"not_analyzed"
            },
            "remarks":{
               "type":"nested",
               "properties":{
                  "remarkId":{
                     "type":"integer"
                  },
                  "customerId":{
                     "type":"integer"
                  },
                  "remarkText":{
                     "type":"string",
                     "index":"analyzed",
                     "analyzer":"nGramAnalyzer",
                     "search_analyzer":"WhitespaceAnalyzer"
                  }
               }
            },
         }
      }
   }
}

My Query:

{
   "from":0,
   "size":100,
   "highlight":{
      "pre_tags":[
         "<b>"
      ],
      "post_tags":[
         "<b>"
      ],
      "fields":{
         "remarks.remarkText":{

         }
      }
   },
   "_source":{
      "exclude":[
         "remarks"
      ]
   },
   "query":{
      "match":{
         "_all":{
            "query":"test",
            "operator":"and"
         }
      }
   }
}

If I query using a nested query, I do get highlights, but I need to search _all. I've tried setting include in parent, include in root, but it didn't make a difference.

I'm excluding remarks because I don't want to actually return them, just their highlights. I've tried the query without the exclude as well.

I only need highlights for the nested object.

Chris Klepeis
  • 9,783
  • 16
  • 83
  • 149
  • I'm not sure if that is possible, have a [look](https://www.elastic.co/guide/en/elasticsearch/guide/current/nested-query.html). – Rob Apr 07 '16 at 14:03
  • Sounds like it should be from here https://www.elastic.co/guide/en/elasticsearch/reference/1.4/mapping-nested-type.html "You may want to index inner objects both as nested fields and as flattened object fields, eg for highlighting. This can be achieved by setting include_in_parent to true" – Chris Klepeis Apr 07 '16 at 14:05

1 Answers1

1

I had to use RequireFieldMatch(false) on the highlight.

Chris Klepeis
  • 9,783
  • 16
  • 83
  • 149