Highlight behavior in Elasticsearch version 6.0.1

I'm facing this issue in Elastic search which I cannot explain. Highlight appears sometimes but other times they do not. Following is the way to reproduce it through kibana. My index and mapping -

PUT test_index
{
  "mappings": {
    "doc": {
      "properties": {
        "type": {
          "type": "text"
        },
        "packages": {
          "type": "nested",
          "include_in_root": true,
          "properties": {
            "amount": {
              "type": "keyword",
              "fields": {
                "raw": { 
                  "type": "double" 
                }
              }
            },
            "rem_amount": {
              "type": "keyword",
              "fields": {
                "raw": { 
                  "type": "double" 
                }
              }
            }
          }
        }
      }
    }
  }
}

Insert sample data

PUT test_index/doc/1
{
  "id": 1,
  "type": "data",
  "packages" : [
    {
      "amount": "100.0",
      "rem_amount": "100.5"
    }
  ]
}

The following queries(Query 1 and Query 2) do not return highlight. Please note I have a larger query. I am pasting just a part of it here.

Query 1: require_field_match: true and fields: ["packages.*"] . Output - No highlight

GET test_index/_search
{
  "query": {
    "query_string": {
      "query": "100",
      "fields": ["packages.*"],
      "type":"phrase_prefix"
    }
  },
  "min_score": 0.000001,
  "highlight" : {
    "require_field_match": true,
    "fields": {
      "*": {
        "type": "plain"
      }
    }
  }
}

Query 2: require_field_match: false and fields: ["packages.*"] . Output - No highlight

GET test_index/_search
{
  "query": {
    "query_string": {
      "query": "100",
      "fields": ["packages.*"],
      "type":"phrase_prefix"
    }
  },
  "min_score": 0.000001,
  "highlight" : {
    "require_field_match": false,
    "fields": {
      "*": {
        "type": "plain"
      }
    }
  }
}

Only in the case where require_field_match: false and I REMOVE line "fields": ["packages.*"] is when the highlights appear:

Query 3

GET test_index/_search
{
  "query": {
    "query_string": {
      "query": "100",
      "type":"phrase_prefix"
    }
  },
  "min_score": 0.000001,
  "highlight" : {
    "require_field_match": false,
    "fields": {
      "*": {
        "type": "plain"
      }
    }
  }
}

highlighted block:

"highlight": {
          "packages.rem_amount": [
            "<em>100.5</em>"
          ],
          "packages.amount": [
            "<em>100.0</em>"
          ]
        }

Can anyone please explain this behavior? Setting require_field_match as false should have returned the highlight in Query 2 as well. In what way are the "fields" column and "require_field_match" influencing this behavior?

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