gpt4 book ai didi

elasticsearch - 使用术语过滤器的 Elasticsearch 过滤查询

转载 作者:行者123 更新时间:2023-12-02 22:24:32 25 4
gpt4 key购买 nike

我的筛选查询确实有问题。当我运行以下查询时:

{
"query":{
"filtered":{
"query":{
"regexp":{
"name":"chri.*"
}
},
"filter":{
"bool":{
"must":[
{"term": { "accountNonLocked": "false" }}
]
}
}
}
},"fields" : ["name", "id", "accountNonLocked","role"],
"from" : 0,
"size" : 10
}

我得到以下回应
{
"took": 4,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1,
"hits": [
{
"_index": "candidatindex",
"_type": "job",
"_id": "54c7867ecfcbbe42dc000478",
"_score": 1,
"fields": {
"name": [
"Christophe toto"
],
"accountNonLocked": [
true
],
"role": [
"DHR"
]
}
},
{
"_index": "candidatindex",
"_type": "job",
"_id": "54c7867ecfcbbe42dc000468",
"_score": 1,
"fields": {
"name": [
"Christophe Toto"
],
"accountNonLocked": [
true
],
"role": [
"CANDIDATE"
]
}
}
]}
}

但是当我在这样的角色上添加过滤器时:
{
"query":{
"filtered":{
"query":{
"regexp":{
"name":"chri.*"
}
},
"filter":{
"bool":{
"must":[
{"term": { "accountNonLocked": "false" }},
{"term": { "role": "CANDIDATE" }}
]
}
}
}
},"fields" : ["name", "id", "accountNonLocked","role"],
"from" : 0,
"size" : 10
}

然后我得到一个空结果:
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}

有人能告诉我我做错了吗?

最佳答案

您的role字段可能是一个analyzed字符串。
所以要么尝试使用小写的值

 {"term": { "role": "candidate" }}

或将 role字段的映射更改为 not_analyzed(您需要重新索引数据以使更改生效)

关于elasticsearch - 使用术语过滤器的 Elasticsearch 过滤查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33262833/

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