我有一个简单的Elasticsearch JSON查询,如下所示:
public class ParcelList extends Parcel
{
ParcelList()
{
parcelList = new ArrayList<Parcel>();
}
public void addBox(int id, char z, int w, int l, int h)
{
parcelList.add(new Box(id,z,w,l,h));
}
如果值(本例中为“a1”)不为空,我该如何执行第二个'必须'标准?
答案 0 :(得分:6)
您可以使用以下方法实现它 -
{
"query": {
"bool": {
"must": [
{
"match": {
"id": "1"
}
},
{
"bool": {
"should": [
{
"missing": {
"field": "tags.name"
}
},
{
"match": {
"tags.name": "a1"
}
}
]
}
}
]
}
}
}
答案 1 :(得分:0)
我不认为“缺失”可用于最新版的Elasticsearch。 但是,可以使用条件子句代替。 https://www.elastic.co/guide/en/elasticsearch/reference/6.3/search-template.html#_conditional_clauses