使用 man ascii 来查看 ASCII 表。

es搜索值为空或包含某一个元素

Elasticsearch | 作者 zzd75090497 | 发布于2020年09月09日 | 阅读数:4648

es存储的某一个字段值为数组,现搜索的时候需要搜索出结果该字段值为空或包含某几个值的数据,该怎么写
例如: "job_type" : ["12","49","67"] 或者 "job_type" : [ ]
需要搜出job_type中包含49的或者为空的数据
已邀请:

pony_maggie - 公众号:犀牛饲养员的技术笔记

赞同来自: zzd75090497

job_type的mapping使用keyword,搜索使用bool term
 
空值的搜索考虑使用painless脚本,判断数组的长度为0

trycatchfinal

赞同来自: xiaoyuer0225

{
"query": {
"bool": {
"should": [
{
"terms": {
"job_type": [
"12",
"49",
"67"
]
}
},
{
"bool": {
"must_not": [
{
"exists": {
"field": "job_type"
}
}
]
}
}
],
"minimum_number_should_match": 1
}
}
}

要回复问题请先登录注册