当前位置 博文首页 > 闫玉林的博客:Elasticsearch实现对某属性等于某值,或为空为nul
QueryBuilders.matchPhraseQuery("organDn",dn);
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
boolQuery.should(QueryBuilders.termQuery("organDn.keyword",dn));
boolQuery.should(QueryBuilders.termQuery("organDn",""));
boolQuery.should(QueryBuilders.boolQuery().mustNot(QueryBuilders.existsQuery("organDn")));
{
"_source": false,
"query": {
"bool": {
"adjust_pure_negative": true,
"boost": 1.0,
"disable_coord": false,
"should": [
{
"term": {
"organDn.keyword": {
"value": "o=532d340fb47ed20e08edbc09d0a37b3b,dc=lonsun,dc=cn",
"boost": 1.0
}
}
},
{
"term": {
"organDn": {
"boost": 1.0,
"value": ""
}
}
},
{
"bool": {
"adjust_pure_negative": true,
"boost": 1.0,
"disable_coord": false,
"must_not": [
{
"exists": {
"boost": 1.0,
"field": "organDn"
}
}
]
}
}
]
}
},
"size": 10
}
like
某值,搜索结构体,should的第一个条件换成 {
"match_phrase": {
"organDn": {
"boost": 1.0,
"query": "o=532d340fb47ed20e08edbc09d0a37b3b,dc=lonsun,dc=cn",
"slop": 0
}
}
}
cs