Highlight issue in nested objects

Hi,

I am facing some problem with highlighting nested values

Mapping

 "acts" : {
            "type" : "nested",
            "include_in_parent" : true,
            "properties" : {
              "value" : {
                "type" : "text",
                "analyzer" : "my_analyzer_acts"
              }
            }
          },

Index Data

  "acts": [
                        {
                            "value": "Civil Procedure Code, 1908 (CPC) - Section 161, Section 173(8), Section 311, Section 319, Section 391"
                        },
                        {
                            "value": "Constitution of India, 1950 - Article 20, Article 21, Article 226, Article 32"
                        },
                        {
                            "value": "Delhi Special Police Establishment Act, 1946 - Section 6"
                        },
                        {
                            "value": "Evidence Act, 1872 - Section 165"
                        },
                        {
                            "value": "Explosive Substances Act, 1908 - Section 3, Section 4"
                        },
                        {
                            "value": "Penal Code, 1860 (IPC) - Section 120B, Section 147, Section 148, Section 149, Section 302, Section 307"
                        }
                    ],

Query

 {
          "nested": {
            "path": "acts", 
            "query": {
              "bool": {
                "must": [ 
                  {
                    "match": {
                      "acts.value": {
                      "query":	"Evidence Act, 1872 section 165",
                      "operator" : "and"
                      }
                    }
                  }
                ]
              }
            }
        }
        },
         
         {
          "nested": {
            "path": "acts", 
            "query": {
              "bool": {
                "must": [ 
                  {
                    "match": {
                      "acts.value": {
                      "query":	"Civil Procedure Code, 1908",
                      "operator" : "and"
                      }
                    }
                  }
                ]
              }
            }
          }
         
         }

Result

"highlight": {
      "acts.value": [
                        "Civil Procedure Code, 1908 (CPC) - <em>Section</em> 161, <em>Section</em> 173(8), <em>Section</em> 311, <em>Section</em> 319, <em>Section</em> 391",
                        "Delhi Special Police Establishment <em>Act,</em> 1946 - <em>Section</em> 6",
                        "<em>Evidence</em> <em>Act,</em> <em>1872</em> - <em>Section</em> <em>165</em>",
                        "Explosive Substances <em>Act,</em> 1908 - <em>Section</em> 3, <em>Section</em> 4",
                        "Penal Code, 1860 (IPC) - <em>Section</em> 120B, <em>Section</em> 147, <em>Section</em> 148, <em>Section</em> 149, <em>Section</em> 302, <em>Section</em> 307"
                    ]
                }

Expected Result-

In above acts "Civil Procedure Code, 1908" exists but its not highlighting.

Here i found some links
[https://github.com/elastic/elasticsearch/issues/5245#issuecomment-54712079]
Elasticsearch highlight with nested objects
but its long back,
Is it possible to highlight all nested values

I tried to reproduce but it works fine for me. Note that you're not highlighting nested values but rather a simple array of values that is present in the root document (you have include_in_parent set to true in the mapping). Can you share the full query with the highlight section as well as the definition for my_analyzer_acts analyzer ?

Hi jimczi,

Thanks for replay, here my my_analyzer_acts mapping and hightlight query

  "my_analyzer_acts" : {
              "filter" : [
                "standard",
                "lowercase",
                "synonym",
                "synonym_acts",
                "no_stem",
                "stemmeroverride",
                "my_snow"
              ],
              "char_filter" : [
                "html_strip",
                "my_char_filter_acts"
              ],
              "type" : "custom",
              "tokenizer" : "whitespace"
            }

  "char_filter" : {
            "my_char_filter_acts" : {
              "type" : "mapping",
              "mappings" : [
                "- => ",
                ". => ",
                ", => ",
                "— => ",
                ": => ",
                "; =>",
                "? => ",
                "* => ",
                "! => ",
                "^ => "
              ]
            },
            "my_char_filter" : {
              "type" : "mapping",
              "mappings" : [
                "- =>"
              ]
            }
          }

"filter" : {
            "synonym_acts" : {
              "format" : "solr",
              "ignore_case" : "true",
              "type" : "synonym",
              "synonyms" : [
                "IPC,Indian Penal Code",
                "CrPC,Code of Criminal Procedure",
                "CPC,Code of Civil Procedure"
              ]
            },
            "stemmeroverride" : {
              "type" : "stemmer_override",
              "rules" : [
                "being=>being",
                "mice=>mouse",
                "feet=>foot",
                "act=>acts",
                "act=>act"
              ]
            },
            "synonym" : {
              "format" : "solr",
              "ignore_case" : "true",
              "type" : "synonym",
              "synonyms" : [
                "Date,dt => Date,dt",
                "co-operate,cooperate => co-operate,cooperate",
                "Dated,dtd => Dated,dtd",
                "Others,Ors => Others,Ors"
              ]
            },
            "my_snow" : {
              "type" : "snowball",
              "language" : "English"
            },
            "no_stem" : {
              "ignore_case" : "true",
              "keywords" : [
                "Writ",
                "Not"
              ],
              "type" : "keyword_marker"
            }

Elastic queries i did in Nest(C#)

  .Highlight(hi => hi.Fields(
                        fi => fi.Field(f => f.acts.Select(y => new ActsInner { value = y.value })).Type("plain").NumberOfFragments(0))

Query in Nest(C#)

.Query(q => q.Bool(b => b.Must(mu => mu.Nested(n => n.Path(x => x.acts).Query(q => q.Bool(b => b.Must(m => m.Match(d => d.Field(f => f.acts.First().value).Query(item).Operator(Operator.And))))))))

ActsInner is list of acts
public class ActsInner
{
public string value { get; set; }
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.