[英]Elasticsearch java top level query
I am trying to run a search on the following json using the java api 我正在尝试使用Java API在以下json上运行搜索
{
"query": {
"has_child": {
"query" : {
"filtered": {
"query": { "match_all": {}},
"filter" : {
"and": {"filters":[
{"term": {"term": "value"}}
]}
}
}
},
"child_type": "child"
}
}
}
Here is the java code I have, 这是我拥有的Java代码,
QueryBuilders.hasChildQuery("child", QueryBuilders
.filteredQuery(QueryBuilders.matchAllQuery(),
FilterBuilders.andFilter(FilterBuilders.
termFilter("term", "value"))));
However this just produces the json 但是这只会产生json
{"has_child":
{"query":
{"filtered":
{"query":{"match_all":{}},
"filter":{
"and":
{"filters":[
{"term":{"term":"value"}}
]
}
}
}
},
"child_type":"child"
}
}
As you can see I am missing a top level { "query" : ... }
but I cannot find out how to add this top level query using the java api for elasticsearch. 如您所见,我缺少顶层{ "query" : ... }
但是我找不到如何使用用于Elasticsearch的Java api添加此顶层查询的方法。
From my understanding inside the code 根据我对代码内部的理解
client.prepareSearch("parent-child")
.setSearchType(SearchType.QUERY_THEN_FETCH)
.setQuery(query)
.setFrom(0).setSize(60).setExplain(true)
.execute()
.actionGet();
It autowraps the query with {"query" : ...}
它使用{"query" : ...}
包装查询
My issue was that I was searching on the wrong index. 我的问题是我在搜索错误的索引。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.