我有一个查询,我想在其中添加一个 Must_not 子句,该子句将丢弃某些字段具有空白数据的所有记录。我尝试了很多方法,但没有一个有效。当我对其他特定字段发出相同的查询(如下所述)时,它工作正常。
此查询应获取没有“registrationType1”字段为空/空白的所有记录
query:
{
"size": 20,
"_source": [
"registrationType1"
],
"query": {
"bool": {
"must_not": [
{
"term": {
"registrationType1": ""
}
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
下面的结果仍然包含带有空值的“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": ""}}**
Run Code Online (Sandbox Code Playgroud)
上述字段的 PFB 映射
"registrationType1": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
}
Run Code Online (Sandbox Code Playgroud)
您需要使用子keyword字段才能执行此操作:
{
"size": 20,
"_source": [
"registrationType1"
],
"query": {
"bool": {
"must_not": [
{
"term": {
"registrationType1.keyword": "" <-- change this
}
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4353 次 |
| 最近记录: |