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.

2
  • I'm not sure if that is possible, have a look. Commented Apr 7, 2016 at 14:03
  • Sounds like it should be from here elastic.co/guide/en/elasticsearch/reference/1.4/… "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" Commented Apr 7, 2016 at 14:05

1 Answer 1

1

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

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

1 Comment

Woot! This was surprising.

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.