[英]elasticsearch highlight property missing in results
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. 如您所见,高亮显示属性完全缺失。
You have too many closing curly brackets in your query part: 在查询部分中有太多的结束花括号:
"query":{
"query_string":{
"query":"foo"
}
} <---- This one is not needed.
},
So the highlight portion is simply ignored by parser. 因此,解析器会忽略突出显示部分。
By the way, the pre_tags
and post_tags
should be arrays: 顺便说一句,
pre_tags
和post_tags
应该是数组:
curl "localhost:9200/twitter/tweet/_search?pretty=true" -d '{
"query": {
"query_string": {
"query": "foo"
}
},
"highlight": {
"pre_tags": ["<b>"],
"post_tags": ["</b>"],
"fields": {
"message": {"number_of_fragments": 20}
}
}
}'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.