gpt4 book ai didi

elasticsearch - 过滤ID值

转载 作者:行者123 更新时间:2023-12-03 00:53:16 25 4
gpt4 key购买 nike

我在使用ID值过滤字段时遇到问题,不确定如何发生,这是映射和示例。

在添加新用户之后可以看出,将primary_user设置为AWBFyulclsp0PJbvPiuB,除非在过滤器请求中使用filter,否则将无法使用keyword来找到它。
这仅在ID值中发生。
此行为的根本原因是什么?

   GET users/_mapping/

Response:
{
...
...
"primary_user": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
------
POST users/user
{
"primary_user": "AWBFyulclsp0PJbvPiuB"
}

Response:
{
"_index": "users",
"_type": "user",
"_id": "AWIaOFgQmedTIIkbtGPG",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"created": true
}
------
GET users/user/_search
{
"query": {
"bool": {
"filter": {
"term": {
"primary_user": "AWBFyulclsp0PJbvPiuB"
}
}
}
}
}
Response:
{
"took": 0,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
------
GET users/user/_search
{
"query": {
"bool": {
"filter": {
"term": {
"primary_user.keyword": "AWBFyulclsp0PJbvPiuB"
}
}
}
}
}

Response:
{
"_index": "users",
"_type": "user",
"_id": "AWIaOFgQmedTIIkbtGPG",
"_score": 0,
"_source": {
"primary_user": "AWBFyulclsp0PJbvPiuB"
}
}

最佳答案

由于primary_user具有文本数据类型,如您的映射中所写:

 "primary_user": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}

因此,您可以更改要查询的字段:
GET users/user/_search
{
"query": {
"bool": {
"filter": {
"term": {
"primary_user.keyword": "AWBFyulclsp0PJbvPiuB"
}
}
}
}
}

或更改术语以匹配查询:
GET users/user/_search
{
"query": {
"bool": {
"filter": {
"match": {
"primary_user": "AWBFyulclsp0PJbvPiuB"
}
}
}
}
}

关于elasticsearch - 过滤ID值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49235835/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com