我正在尝试执行以下操作
curl -X POST localhost:9200/magento/customer/_search?pretty=1 -d '
{
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "john",
"fields": [
"firstname"
],
"type": "phrase_prefix"
}
}
],
"should": [
{
"multi_match": {
"query": "bro",
"fields": [
"lastname"
],
"type": "phrase_prefix",
"boost": 10
}
},
{
"multi_match": {
"query": "sul",
"fields": [
"lastname"
],
"type": "phrase_prefix",
"boost": 1
}
}
]
}
}
}
'
它在 Johnnie BrousXXXX(已编辑)之前向我返回了 Johnnie SultXXXX 的结果。
似乎没有正确应用提升?我试过在布尔值上查看弹性搜索文档: http ://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html
他们有一个没有任何意义boost
的节点下,你通常想提升一个特定的布尔值...?bool
should
更新:
创建索引时我没有创建任何字段映射。
以下是 的结果explain
:
{
"ok": true,
"_index": "magento",
"_type": "customer",
"_id": "6043",
"matched": true,
"explanation": {
"value": 2.3943894,
"description": "product of:",
"details": [
{
"value": 3.591584,
"description": "sum of:",
"details": [
{
"value": 1.795792,
"description": "sum of:",
"details": [
{
"value": 1.795792,
"description": "weight(firstname:johnnie in 8931) [PerFieldSimilarity], result of:",
"details": [
{
"value": 1.795792,
"description": "score(doc=8931,freq=1.0 = termFreq=1.0\n), product of:",
"details": [
{
"value": 0.18156901,
"description": "queryWeight, product of:",
"details": [
{
"value": 9.89041,
"description": "idf(docFreq=1, maxDocs=14524)"
},
{
"value": 0.018358087,
"description": "queryNorm"
}
]
},
{
"value": 9.89041,
"description": "fieldWeight in 8931, product of:",
"details": [
{
"value": 1,
"description": "tf(freq=1.0), with freq of:",
"details": [
{
"value": 1,
"description": "termFreq=1.0"
}
]
},
{
"value": 9.89041,
"description": "idf(docFreq=1, maxDocs=14524)"
},
{
"value": 1,
"description": "fieldNorm(doc=8931)"
}
]
}
]
}
]
}
]
},
{
"value": 1.795792,
"description": "sum of:",
"details": [
{
"value": 1.795792,
"description": "weight(lastname:sultXXXX in 8931) [PerFieldSimilarity], result of:",
"details": [
{
"value": 1.795792,
"description": "score(doc=8931,freq=1.0 = termFreq=1.0\n), product of:",
"details": [
{
"value": 0.18156901,
"description": "queryWeight, product of:",
"details": [
{
"value": 9.89041,
"description": "idf(docFreq=1, maxDocs=14524)"
},
{
"value": 0.018358087,
"description": "queryNorm"
}
]
},
{
"value": 9.89041,
"description": "fieldWeight in 8931, product of:",
"details": [
{
"value": 1,
"description": "tf(freq=1.0), with freq of:",
"details": [
{
"value": 1,
"description": "termFreq=1.0"
}
]
},
{
"value": 9.89041,
"description": "idf(docFreq=1, maxDocs=14524)"
},
{
"value": 1,
"description": "fieldNorm(doc=8931)"
}
]
}
]
}
]
}
]
}
]
},
{
"value": 0.6666667,
"description": "coord(2/3)"
}
]
}
}
我知道should
s 是匹配的,因为没有它们,我得到的第一个结果与使用它们不同。
我希望我phrase_prefix
在这种情况下正确使用。从文档中我并不完全清楚。此页面引用它们(http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-match-query.html#_match_phrase_prefix),但仅在常规上下文中query
,而不是在multi_match
.