Highlights not returned for multiple queries on the same JSON object field

Hi all,

I have the following query:

With ES 7.5

"query": {
    "bool": {
      "must": [
        {
          "term": {
            "siren": "493754261"
          }
        }
      ],
      "should": [
        {
          "multi_match": {
            "type": "phrase",
            "query": "transfert du protefeuille",
            "fields": [
              "doc.*"
            ]
          }
        },
        {
          "multi_match": {
            "type": "cross_fields",
            "query": "Acquisition Fusion Cession Fusion-acquisition Leverage buy out LBO Transfert portefeuille",
            "fields": [
              "doc.*"
            ]
          }
        }
      ]
    }
  }

and the following mapping for the doc object:

 other fields here,

...

 "doc" : {
          "properties" : {
            "0" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "1" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
	...
 "n" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
...
other fields here,

The query works fine but if I add a highlights it doens't highlight anything at all.
I tried also to put the query in a highlight_query but the result is not correct neither.

Any ideas ?

Thanks a lot for your help

Christophe

Just tried with your mapping & query, i don't see the issue, could you please provide more details

{
  "took" : 15,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 4.746754,
    "hits" : [
      {
        "_index" : "siren_index",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 4.746754,
        "_source" : {
          "siren" : "493754261",
          "doc" : {
            "0" : "transfert du protefeuille",
            "1" : "Acquisition Fusion Cession Fusion-acquisition Leverage buy out LBO Transfert portefeuille"
          }
        },
        "highlight" : {
          "doc.1.keyword" : [
            "<em>Acquisition Fusion Cession Fusion-acquisition Leverage buy out LBO Transfert portefeuille</em>"
          ],
          "doc.0.keyword" : [
            "<em>transfert du protefeuille</em>"
          ],
          "doc.0" : [
            "<em>transfert</em> <em>du</em> <em>protefeuille</em>"
          ]
        }
      }
    ]
  }
}


GET siren_index/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "siren": "493754261"
          }
        }
      ],
      "should": [
        {
          "multi_match": {
            "type": "phrase",
            "query": "transfert du protefeuille",
            "fields": [
              "doc.*"
            ]
          }
        },
        {
          "multi_match": {
            "type": "cross_fields",
            "query": "Acquisition Fusion Cession Fusion-acquisition Leverage buy out LBO Transfert portefeuille",
            "fields": [
              "doc.*"
            ]
          }
        }
      ]
    }
  },
  "highlight": {
    "fields": {
      "doc.*": {}
    }
  }
}
PUT siren_index/_doc/1
{
  "siren": "493754261",
  "doc": {
    "0": "transfert du protefeuille",
    "1": "Acquisition Fusion Cession Fusion-acquisition Leverage buy out LBO Transfert portefeuille"
  }
}
PUT siren_index
{
  "mappings": {
    "properties": {
      "siren": {
        "type": "keyword"
      },
      "doc": {
        "properties": {
          "0": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "1": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
      }
    }
  }
}

Hi Yassine,

Thanks for your fast response.

Regarding what you did, if I put a second document like this :

PUT siren_index/_doc/2
{
  "siren": "493754261",
  "doc": {
    "0": "lgkjsdlkgj kldgjlmdskgj",
    "3": "Acquisition dfgsqhjdfgjhfg Cession Fusionacquisition "
  }
}

I have this result :

  "hits" : [
      {
        "_index" : "siren_index",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 6.0535626,
        "_source" : {
          "siren" : "493754261",
          "doc" : {
            "0" : "transfert du protefeuille",
            "1" : "Acquisition Fusion Cession Fusion-acquisition Leverage buy out LBO Transfert portefeuille"
          }
        },
        "highlight" : {
          "doc.1.keyword" : [
            "<em>Acquisition Fusion Cession Fusion-acquisition Leverage buy out LBO Transfert portefeuille</em>"
          ],
          "doc.0.keyword" : [
            "<em>transfert du protefeuille</em>"
          ],
          "doc.0" : [
            "<em>transfert</em> <em>du</em> <em>protefeuille</em>"
          ]
        }
      },
      {
        "_index" : "siren_index",
        "_type" : "_doc",
        "_id" : "2",
        "_score" : 1.0453678,
        "_source" : {
          "siren" : "493754261",
          "doc" : {
            "0" : "lgkjsdlkgj kldgjlmdskgj",
            "3" : "Acquisition dfgsqhjdfgjhfg Cession Fusionacquisition "
          }
        }
      }
    ]

The result of the query is corrrect but not the highlighting. What I would like to have is :

  "hits" : [
      {
        "_index" : "siren_index",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 6.0535626,
        "_source" : {
          "siren" : "493754261",
          "doc" : {
            "0" : "transfert du protefeuille",
            "1" : "Acquisition Fusion Cession Fusion-acquisition Leverage buy out LBO Transfert portefeuille"
          }
        },
        "highlight" : {
          "doc.0" : [
            "<em>transfert du protefeuille</em>"
          ],
          "doc.1" : [
            "<em>Acquisition</em> <em>Fusion</em> <em>Cession</em> <em> Fusion-acquisition</em> <em>Leverage</em> <em>buy</em> <em>out</em> <em>LBO</em> <em>Transfert portefeuille</em>"
          ]
        }
      },
      {
        "_index" : "siren_index",
        "_type" : "_doc",
        "_id" : "2",
        "_score" : 1.0453678,
        "_source" : {
          "siren" : "493754261",
          "doc" : {
            "0" : "lgkjsdlkgj kldgjlmdskgj",
            "3" : "Acquisition dfgsqhjdfgjhfg Cession Fusionacquisition "
          }
        }
      },
        "highlight" : {
          "doc.1" : [
            "<em>Acquisition</em> <em>Cession</em> <em> Fusion-acquisition</em> 
          ]
        }
      }
    ]

thanks for your help

Christophe

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