我有两个字段: id
以及 code
. code
用作主键( _id
)我也是。当我经过时 id
我可以得到结果,但如果我通过 code
一无所获。这是工作,但没有理由或改变停止工作。
elasticsearch版本:7.1
文件编号:
{
"id": 123,
"code": "AAAEEXXX",
"name": "Sample name"
}
搜索查询依据 id
作品。
{
"query": {
"bool": {
"must": {
"term": {
"id": 123
}
}
}
}
}
结果来自 id
查询:
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 1.0,
"hits": [
{
"_index": "test-index",
"_type": "_doc",
"_id": "AAAEEXXX",
"_score": 1.0,
"_source": {
"id": 123,
"code": "AAAEEXXX",
"name": "Sample name"
}
}
]
}
}
但是,如果我搜索 code
不起作用。
按代码查询:
{
"query": {
"bool": {
"must": {
"term": {
"code": "AAAEEXXX"
}
}
}
}
}
结果来自 code
查询:
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 0,
"relation": "eq"
},
"max_score": null,
"hits": []
}
}
1条答案
按热度按时间qvtsj1bj1#
使用
.keyword
精确匹配的Map如下: