I'm using _analyzer field to specify which analyzer to be used for the document when indexing.
I need to use this feature because I don't know which language the document is written in, until I index it.
With this setting, I'm not getting "highlight" field when I query.
Please help me out and let me know how I can get highlighting.
Here's my unsuccessful attempt:
$ curl -XPUT 'http://localhost:9200/test/'
{"ok":true,"acknowledged":true}
$
$ curl -XPUT 'http://localhost:9200/test/1/_mapping' -d '{"1":{"properties":{"content":{"type":"string","store":"yes","index":"analyzed"}}}}'
{"ok":true,"acknowledged":true}
$
$ curl -XPUT 'http://localhost:9200/test/1/1' -d '{"content":"I worked from home on the other day.","_analyzer":"english"}'
{"ok":true,"_index":"test","_type":"1","_id":"1","_version":1}
$
$ curl -XGET 'http://localhost:9200/test/1/_search?pretty=true' -d '{"query":{"text":{"content":{"query":"working","analyzer":"english"}}},"highlight":{"fields":{"content":{}}},"fields":["content","highlight"]}'
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 0.11506981,
"hits" : [ {
"_index" : "test",
"_type" : "1",
"_id" : "1",
"_score" : 0.11506981,
"fields" : {
"content" : "I worked from home on the other day."
}
} ]
}
}
As you can see, there is no "highlight" field in the result.
Here's the working case, where I specify the analyzer in the mapping explicitly:
$ curl -XPUT 'http://localhost:9200/test/'
{"ok":true,"acknowledged":true}
$ curl -XPUT 'http://localhost:9200/test/1/_mapping' -d '{"1":{"properties":{"content":{"type":"string","store":"yes","index":"analyzed","analyzer":"english"}}}}'
{"ok":true,"acknowledged":true}
$ curl -XPUT 'http://localhost:9200/test/1/1' -d '{"content":"I worked from home on the other day."}'
{"ok":true,"_index":"test","_type":"1","_id":"1","_version":1}
$ curl -XGET 'http://localhost:9200/test/1/_search?pretty=true' -d '{"query":{"text":{"content":"working"}},"highlight":{"fields":{"content":{}}},"fields":["content","highlight"]}'
{
"took" : 53,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 0.11506981,
"hits" : [ {
"_index" : "test",
"_type" : "1",
"_id" : "1",
"_score" : 0.11506981,
"fields" : {
"content" : "I worked from home on the other day."
},
"highlight" : {
"content" : [ "I worked from home on the other day." ]
}
} ]
}
}