ElasticSearch Java Client查询嵌套对象

如何转换这种查询。

{

"query": {

"nested": {

"path": "consultations",

"query": {

"bool": {

"must": [

{

"match": {

"consultations.prescriptions": "alfuorism"

}

},

{

"match": {

"consultations.Diagnosis": "Fever"

}

}

]

}

}

}

}

}

使用QueryBuilders进行Java客户端查询

回答:

以下Java代码将生成您的查询

public NestedQueryBuilder nestedBoolQuery(final Map<String, String> propertyValues, final String nestedPath) {

BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();

Iterator<String> iterator = propertyValues.keySet().iterator();

while (iterator.hasNext()) {

String propertyName = iterator.next();

String propertValue = propertyValues.get(propertyName);

MatchQueryBuilder matchQuery = QueryBuilders.matchQuery(propertyName, propertValue);

boolQueryBuilder.must(matchQuery);

}

return QueryBuilders.nestedQuery(nestedPath, boolQueryBuilder);

}

参数propertyValues为:

Map<String, String> propertyValues = new HashMap<String, String>();

propertyValues.put("consultations.prescriptions", "alfuorism");

propertyValues.put("consultations.Diagnosis", "Fever");

参数nestedPath为:

consultations

以上是 ElasticSearch Java Client查询嵌套对象 的全部内容, 来源链接: utcz.com/qa/427855.html

回到顶部