I have trouble getting elasticsearch results highlighting to work. I have found many examples and tried different versions but I fail applying it to my own index. What am I doing wrong?
Here is my test script:
init() {
curl -XDELETE http://localhost:9200/twitter
echo
curl -XPUT http://localhost:9200/twitter
echo
curl -XPUT http://localhost:9200/twitter/tweet/_mapping -d '{
"tweet" : {
"properties" : {
"user" : { "type" : "string" },
"message" : {
"type" : "string",
"index": "analyzed",
"store": "yes",
"term_vector" : "with_positions_offsets"
}
}
}
}'
echo
curl -XPOST http://localhost:9200/twitter/tweet -d '{
"user": "kimchy",
"message": "You know, for Search"
}'
echo
curl -XPOST http://localhost:9200/twitter/tweet -d '{
"user": "bar",
"message": "You know, foo for Search"
}'
echo
sleep 2
echo '-------------------'
}
[ "$1" = "init" ] && init
curl -X GET 'http://localhost:9200/twitter/_search/?pretty=true' -d '{
"query":{
"query_string":{
"query":"foo"
}
}
},
"highlight":{
"pre_tags": "<b>",
"post_tags": "</b>",
"fields" : {
"message" : {"number_of_fragments": 20}
}
}
}'
and here the output:
{
"took" : 4,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 0.09492774,
"hits" : [ {
"_index" : "twitter",
"_type" : "tweet",
"_id" : "1tgGWGhnRLy-nJIAunFeeQ",
"_score" : 0.09492774, "_source" : {
"user": "bar",
"message": "You know, foo for Search"
}
} ]
}
}%
As you can see the highlight property is missing completely.