[英]ElasticSearch returning no result when search by a particular field
我有两个字段的文档: id
和code
。 code
也用作主键( _id
)。 当我按id
搜索时,我可以获得结果,但如果我按code
搜索,则不会返回任何内容。 这是有效的,但没有理由或更改停止工作。
弹性搜索版本: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": []
}
}
使用.keyword
映射进行精确匹配,如下所示:
{
"query": {
"bool": {
"must": {
"term": {
"code.keyword": "AAAEEXXX" <--
}
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.