gpt4 book ai didi

elasticsearch - Elasticsearch --- : MUST_NOT query not working

转载 作者:行者123 更新时间:2023-11-29 02:55:58 24 4
gpt4 key购买 nike

我有一个查询,我想在其中添加一个 must_not 子句,该子句将丢弃在某些字段中具有空白数据的所有记录。我尝试了很多方法,但都没有用。当我对其他特定字段发出相同的查询(如下所述)时,它工作正常。

此查询应获取所有“registrationType1”字段不为空/空白的记录

query:
{
"size": 20,
"_source": [
"registrationType1"
],
"query": {
"bool": {
"must_not": [
{
"term": {
"registrationType1": ""
}
}
]
}
}
}

下面的结果仍然包含空值的“registrationType1”

results:

**"_source": {
"registrationType1": ""}}
, * {
"_index": "oh_animal",
"_type": "animals",
"_id": "3842002",
"_score": 1,
"_source": {
"registrationType1": "A&R"}}
, * {
"_index": "oh_animal",
"_type": "animals",
"_id": "3842033",
"_score": 1,
"_source": {
"registrationType1": "AMHA"}}
, * {
"_index": "oh_animal",
"_type": "animals",
"_id": "3842213",
"_score": 1,
"_source": {
"registrationType1": "AMHA"}}
, * {
"_index": "oh_animal",
"_type": "animals",
"_id": "3842963",
"_score": 1,
"_source": {
"registrationType1": ""}}
, * {
"_index": "oh_animal",
"_type": "animals",
"_id": "3869063",
"_score": 1,
"_source": {
"registrationType1": ""}}**

上面字段的 PFB 映射

"registrationType1": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
}

最佳答案

您需要使用 keyword 子字段来执行此操作:

{
"size": 20,
"_source": [
"registrationType1"
],
"query": {
"bool": {
"must_not": [
{
"term": {
"registrationType1.keyword": "" <-- change this
}
}
]
}
}
}

关于elasticsearch - Elasticsearch --- : MUST_NOT query not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57805851/

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