假设我们在弹性索引中有以下格式的文档:
{
"street": "Adenauer Allee",
"number": "119",
"zipcode": "53113"
}
我们有一个类似的查询:
{
"from": 0,
"size": 1,
"query": {
"bool": {
"must": [
{
"match": {
"zipcode": {
"query": "53113",
"fuzziness": "0"
}
}
},
{
"match": {
"street": {
"query": "Adenauer Allee",
"fuzziness": "auto"
}
}
}
],
"should": [
{
"match": {
"number": {
"query": "119"
}
}
}
]
}
}
}
现在假设我们的索引包含 3 个文档
street: "Adenauer Allee"
zipcode: "53113"
他们有不同的门牌号码,例如:
doc1: number: "11"
doc2: number: "120"
doc3: number: "10a"
(注意 doc3 中的“a”)。
上面的查询将返回带有数字“11”的结果doc1(因为它更接近字母数字)。
期望的行为是首先返回具有最接近数值的文档。在上述场景中,这是编号为“120”的doc2。
我怎样才能做到这一点?
弹性搜索信息:
{
"name": "193a315bccae",
"cluster_name": "demo",
"cluster_uuid": "kg3tZZOyqOgqTbn_elqs_g",
"version": {
"number": "7.5.1",
"build_flavor": "default",
"build_type": "docker",
"build_hash": "3ae9ac9a93c95bd0cdc054951cf95d88e1e18d96",
"build_date": "2019-12-16T22:57:37.835892Z",
"build_snapshot": false,
"lucene_version": "8.3.0",
"minimum_wire_compatibility_version": "6.8.0",
"minimum_index_compatibility_version": "6.0.0-beta1"
},
"tagline": "You Know, for Search"
}