elastic / elasticsearch

Free and Open Source, Distributed, RESTful Search Engine
https://www.elastic.co/products/elasticsearch
Other
1.15k stars 24.84k forks source link

Highlighting on `match_phrase` with `index_phrases` enabled does not seem to work #40227

Open loren opened 5 years ago

loren commented 5 years ago

Elasticsearch version (bin/elasticsearch --version):

Version: 6.6.0, Build: default/tar/a9861f4/2019-01-24T11:27:09.439740Z, JVM: 1.8.0_112

Plugins installed: []

JVM version (java -version):

java version "1.8.0_112"
Java(TM) SE Runtime Environment (build 1.8.0_112-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.112-b16, mixed mode)

OS version (uname -a if on a Unix-like system):

Darwin compy.local 18.2.0 Darwin Kernel Version 18.2.0: Thu Dec 20 20:46:53 PST 2018; root:xnu-4903.241.1~1/RELEASE_X86_64 x86_64

Description of the problem including expected versus actual behavior: When I index a text field with index_phrases enabled, query it with match_phrase, and request highlighting, Elasticsearch does not return any highlights with the hit. I expected a highlight to be returned. When I query the same field with match instead of match_phrase, Elasticsearch returns the expected highlight.

When I index the same text field without index_phrases, query it with match_phrase, and request highlighting, Elasticsearch returns the expected highlight.

Initially posted here.

Steps to reproduce:

DELETE test
PUT test
{
  "mappings": {
    "_doc": {
      "properties": {
        "voter": {
          "type": "text",
          "index_phrases": true
        }
      }
    }
  }
}

PUT test/_doc/1?refresh
{
  "voter": "John Paul Jones"
}

POST test/_search
{
  "query": {
    "match_phrase": {
      "voter": "Paul Jones"
    }
  },
  "highlight": {
    "fields": {
      "voter": {}
    }
  }
}
elasticmachine commented 5 years ago

Pinging @elastic/es-search

loren commented 5 years ago

One possible workaround for the query_string queries I have is to use a highlight_query like this:

POST test/_search
{
  "query": {
    "query_string": {
      "query": """ "paul jones" """
    }
  },
  "highlight": {
    "fields": {
      "voter": {
        "highlight_query": {
          "match": {
            "voter": """ "paul jones" """
          }
        }
      }
    }
  }
}

The match doesn't care about phrases and will just find and highlight individual words.

mayya-sharipova commented 8 months ago

It is still the issue in 8.12

elasticsearchmachine commented 4 months ago

Pinging @elastic/es-search-relevance (Team:Search Relevance)