不为失败找理由,要为成功找方法。

关于phrase_prefix的两种查询方式,结果为什么不同?

Elasticsearch | 作者 方磊 | 发布于2017年08月02日 | 阅读数:3909

第一个查询json:
 {
"fields": ["nickName"],
"query": {
"match": {
"nickName": {
"query": "刘开",
"type": "phrase_prefix",
"slop": 3,
"max_expansions": 10
}
}
}
}
结果为:
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 4,
"successful": 4,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 59.365772,
"hits": [
{
"_index": "user",
"_type": "user",
"_id": "7751349294733a974d05e7850a5332189",
"_score": 59.365772,
"fields": {
"nickName": [
"刘开友"
]
}
},
{
"_index": "user",
"_type": "user",
"_id": "96cec51d74c78848f72a2cd17a4095931",
"_score": 58.98803,
"fields": {
"nickName": [
"刘开朋"
]
}
},
{
"_index": "user",
"_type": "user",
"_id": "7471f9c744f86845a7c8608d9c1f62861",
"_score": 26.267944,
"fields": {
"nickName": [
"刘青松新的开始"
]
}
}
]
}
}
第而个查询json:
{
"fields": ["nickName"],
"query": {
"match_phrase_prefix": {
"nickName": "刘开"
}
}
}
结果为:
{
"took": 6,
"timed_out": false,
"_shards": {
"total": 4,
"successful": 4,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 231.7211,
"hits": [
{
"_index": "user",
"_type": "user",
"_id": "655c928624b97964d00c02eff7a025730",
"_score": 231.7211,
"fields": {
"nickName": [
"刘开明"
]
}
},
{
"_index": "user",
"_type": "user",
"_id": "96cec51d74c78848f72a2cd17a4095931",
"_score": 185.37688,
"fields": {
"nickName": [
"刘开朋"
]
}
},
{
"_index": "user",
"_type": "user",
"_id": "7751349294733a974d05e7850a5332189",
"_score": 183.16644,
"fields": {
"nickName": [
"刘开友"
]
}
}
]
}
}

我以为这两种查询结果是一致的.可以搜出来的结果稍有差异,有谁知道这两个查询json的区别吗? java好像只能构建第一种json,而无法构建第二种json,但是我需要第二种json的java构建方式

 
已邀请:

medcl - 今晚打老虎。

赞同来自:

你把参数:
"slop": 3, "max_expansions": 10
去掉就一致了,你用的什么JAVA API呢?
 

要回复问题请先登录注册