0

I can't get this to highlight for the life of me. It seems like elastic search is broken with regards to highlighting on fields that are mentioned in a filtered clause. The below query just does not highlight. Is this an issue with Elastic? What can I do to make this work?

    {
  "query": {
    "filtered": {
      "query": {
        "bool": {
          "must": [
            {
              "term": {
                "language": "Austrian"
              }
            }
          ]
        }
      },
      "filter": {
        "and": [
          {
            "query": {
              "query_string": {
                "fields": [
                  "standard_analyzed_name",
                  "standard_analyzed_message"
                ],
                "query": "Arnold AND Schwarz"
              }
            }
          }
        ]
      }
    }
  },
  "size": 20,
  "sort": [
    {
      "total_interactions": {
        "order": "desc"
      }
    }
  ],
  "highlight": {
    "fields": {
      "standard_analyzed_name": {
        "pre_tags": [
          "<strong>"
        ],
        "post_tags": [
          "</strong>"
        ],
        "fragment_size": 500,
        "number_of_fragments": 1
      },
      "standard_analyzed_message": {
        "pre_tags": [
          "<strong>"
        ],
        "post_tags": [
          "</strong>"
        ],
        "fragment_size": 500,
        "number_of_fragments": 1
      }
    }
  }
}

UPDATE

The above query does highlight in elastic search 2.0.0 - Yayyy

3
  • Can you share your mapping and some documents that might be helpful to reproduce your case? Commented Nov 12, 2015 at 3:29
  • Thanks, what about your mapping? curl -XGET localhost:9200/facebook_posts/_mapping/document Commented Nov 12, 2015 at 3:57
  • Here is the data: gist.githubusercontent.com/imtiazahmad007/8463cde239399a685f0d/… Commented Nov 12, 2015 at 14:21

1 Answer 1

1

Well, simply put, you have your query and filter parts swapped. Your query_string should go inside the query part and the term should go inside the filter part, then all will be well and you'll see the highlighted fields.

{
   "query": {
      "filtered": {
         "query": {
            "query_string": {
               "fields": [
                  "standard_analyzed_name",
                  "standard_analyzed_message"
               ],
               "query": "arnold"
            }
         },
         "filter": {
            "term": {
               "language": "austrian"
            }
         }
      }
   },
   "size": 20,
   "sort": [
      {
         "total_interactions": {
            "order": "desc"
         }
      }
   ],
   "highlight": {
      "fields": {
         "standard_analyzed_name": {
            "pre_tags": [
               "<strong>"
            ],
            "post_tags": [
               "</strong>"
            ],
            "fragment_size": 500,
            "number_of_fragments": 3
         },
         "standard_analyzed_message": {
            "pre_tags": [
               "<strong>"
            ],
            "post_tags": [
               "</strong>"
            ],
            "fragment_size": 500,
            "number_of_fragments": 3
         }
      }
   }
}
Sign up to request clarification or add additional context in comments.

19 Comments

Thanks, but my query should have still worked. Highlight seems to be kind of picky.. Would you be able to elaborate on this a little further?
That does not return any data.
With arnold and austrian both in lowercase, I do get one result and one highlighted field: "I like <strong>Arnold</strong>"
I modified my query. Notice the query": "Arnold AND Schwarz. Using the and keyword. This is a result of an API i'm writing for elastic. Does this query condition still work for you?
If I'm not mistaken, there is no Schwarz in the document about Arnold that you shared earlier.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.