0
votes

I must be missing something here, but when I try to get highlighting on a search with Elasticsearch, I'm not seeing any highlighting at all, but no errors either. I don't think it's a Tire issue, but I mention Tire just in case it's important. The indexing using Tire is pretty simple (some fields taken out for brevity):

mapping :_source => { :excludes => ['attachment'] } do
  indexes :id, :type => 'integer'
  indexes :title, :store => true
  indexes :attachment, :type => 'attachment', :_source => { :enabled => false }
end

Using curl, I can try this query, which works fine but there's no highlighting in the results:

curl -XPOST http://localhost:9200/myobject/_search\?pretty\=true -d '{             
  "query": {"query_string": {"query": "foobar"}},
  "highlight": {"fields": {"Title":{}}}
}'

Note that I added the ":store => true" in the mapping just to make sure, though I don't think it should be necessary to make highlighting work. So I'm guessing I'm missing something either in the mapping or in the query specification, but I'm not seeing it. Any suggestions would be very much appreciated. Thanks.

1

1 Answers

2
votes

Field names are case-sensitive in elasticsearch. Title and title are two different fields. Try this query:

curl -XPOST http://localhost:9200/myobject/_search\?pretty\=true -d '{             
  "query": {"query_string": {"query": "foobar"}},
  "highlight": {"fields": {"title":{}}}
}