Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no highlights with a highlight prefix query and FVH when no match found #25171

Closed
v1r opened this issue Jun 10, 2017 · 1 comment

Comments

Projects
None yet
3 participants
@v1r
Copy link

commented Jun 10, 2017

Following this issue: #25088

Elasticsearch version: 5.4.0 and 5.4.1
JVM version: 1.8
OS version : Windows 7

No highlights returned using a prefix in a highlight_query when a document attribute has an empty value or no match found

Steps to reproduce:

Create the following index

PUT foo
{
  "mappings": {
    "blogpost": { 
      "properties": { 
        "title": { "type": "text", "term_vector": "with_positions_offsets"}, 
        "description":  { "type": "text", "term_vector": "with_positions_offsets"  }
      }
    }
  }
}

Add a new document, notice description is empty (no match for 'sq' string).

PUT foo/entry/1
{
  "title": "SQ05_H04_WorldTour test",
  "description": ""
}

Run the following query to highlight the string containing 'sq'.

GET foo/_search
{
   "query":{
      "match_all":{ }
   },
   "highlight":{
      "fields":{
         "title":{
            "number_of_fragments":10,
            "type":"fvh",
            "highlight_query":{
               "prefix":{
                  "title":"sq"
               }
            }
         },
         "description":{
            "number_of_fragments":10,
            "type":"fvh",
            "highlight_query":{
               "prefix":{
                  "description":"sq"
               }
            }
         }
      },
      "require_field_match":false
   }
}

The result as expected highlights the string containing 'sq'

{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 1,
    "hits": [
      {
        "_index": "foo",
        "_type": "entry",
        "_id": "1",
        "_score": 1,
        "_source": {
          "title": "SQ05_H04_WorldTour test",
          "description": ""
        },
        "highlight": {
          "title": [
            "<em>SQ05_H04_WorldTour</em> test"
          ]
        }
      }
    ]
  }
}

Lets re-execute the same query, but this time we change the order of fields..

GET foo/_search
{
   "query":{
      "match_all":{ }
   },
   "highlight":{
      "fields":{
         "description":{
            "number_of_fragments":10,
            "type":"fvh",
            "highlight_query":{
               "prefix":{
                  "description":"sq"
               }
            }
         },
         "title":{
            "number_of_fragments":10,
            "type":"fvh",
            "highlight_query":{
               "prefix":{
                  "title":"sq"
               }
            }
         }
      },
      "require_field_match":false
   }
}

Surprisingly, no highlighs returned..

{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 1,
    "hits": [
      {
        "_index": "foo",
        "_type": "entry",
        "_id": "1",
        "_score": 1,
        "_source": {
          "title": "SQ05_H04_WorldTour test",
          "description": ""
        }
      }
    ]
  }
}

is this is a bug? same behavior in 2.x

@v1r v1r changed the title no highlights with a highlight prefix query and FVH when a document attribute as an empty value no highlights with a highlight prefix query and FVH when no match found Jun 10, 2017

@v1r

This comment has been minimized.

Copy link
Author

commented Jun 12, 2017

This is also true for multi terms query like wildcard, regexp

jimczi added a commit to jimczi/elasticsearch that referenced this issue Jun 13, 2017

FastVectorHighlighter should not cache the field query globally
This commit removes the global caching of the field query and replaces it with
a caching per field. Each field can use a different `highlight_query` and the rewriting of
some queries (prefix, automaton, ...) depends on the targeted field so the query used for highlighting
must be unique per field.
There might be a small performance penalty when highlighting multiple fields since the query needs to be rewritten
once per highlighted field with this change.

Fixes elastic#25171

jimczi added a commit that referenced this issue Jun 14, 2017

FastVectorHighlighter should not cache the field query globally (#25197)
This commit removes the global caching of the field query and replaces it with
a caching per field. Each field can use a different `highlight_query` and the rewriting of
some queries (prefix, automaton, ...) depends on the targeted field so the query used for highlighting
must be unique per field.
There might be a small performance penalty when highlighting multiple fields since the query needs to be rewritten
once per highlighted field with this change.

Fixes #25171
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.