如何转换此类查询。
{
"query": {
"nested": {
"path": "consultations",
"query": {
"bool": {
"must": [
{
"match": {
"consultations.prescriptions": "alfuorism"
}
},
{
"match": {
"consultations.Diagnosis": "Fever"
}
}
]
}
}
}
}
}
使用QueryBuilders
进行Java客户端查询答案 0 :(得分:11)
下面的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