elastic / elasticsearch

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

Highlight not working along with term lookup filter #15270

Closed shagga closed 8 years ago

shagga commented 8 years ago

Hi All, I'm new to elastic search and have started exploring it from the past few days. My requirement is to get the matched keywords using term lookup highlighted.

So have 2 indices

http://localhost:9200/lookup/type/1?pretty Output { "_index" : "lookup", "_type" : "type", "_id" : "1", "_version" : 1, "found" : true, "_source":{"terms":["Apache Storm","Kafka","MR","Pig","Hive","Hadoop","Mahout"]} }

And another one as following:-

http://localhost:9200/skillsetanalyzer/resume/_search?fields=keySkills output {"took":19,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":3,"max_score":1.0,"hits":[{"_index":"skillsetanalyzer","_type":"resume","_id":"1","_score":1.0,"fields":{"keySkills":["Core Java","J2EE","Struts 1.x","SOAP based Web Services using JAX-WS","Maven","Ant","JMS","Apache Storm","Kafka","RDBMS (MySQL","Tomcat","Weblogic","Eclipse","Toad","TIBCO product Suite (Administrator","Business Work","Designer","EMS)","CVS","SVN"]}},

And below query returns the correct results but does not highlight the matched keywords.

curl -XGET 'localhost:9200/skillsetanalyzer/resume/_search?pretty' -d ' {

"query": {"filtered": {"filter": {"terms": {"keySkills": {"index":"lookup", "type":"type", "id":"1", "path":"terms" }, "_cache_key":"1" } } } }, "highlight": { "fields":{ "keySkills":{} } } }'

Field "KeySkills" is not analyzed and its type is String. I'm not able to make out what is wrong with the query. Please help in providing the necessary pointers.

Thanks !!

nik9000 commented 8 years ago

A couple of things:

  1. This is probably something better asked on the forum. In general highlighting is funky and its kind of "best effort" so this isn't so much a bug as yet another wart. But its cool to keep it here because most of the rest of Elasticsearch is less funky and things should work.
  2. You should totally surround stuff in `` for multiline code blocks or for inline code blocks. It makes reading these easier.
  3. Requests you include in issues should include the pretty url parameter. The responses should be generated with that. They are so much easier to scan!
  4. I think your issue is actually caused by the way in which highlighting extracts the terms to highlight - can you try using the terms query instead of the terms filter?
shagga commented 8 years ago

Thanks Nik !! I'll take care of the points in future. HIghlighting worked with term query.