Ich habe einen Test gemacht, um zu testen, dass ich die korrekte benannte Abfrage innerhalb einer hasParentQuery erhalte. Aber es scheint, dass es nicht funktioniert.Elasticsearch namens Abfragen in hasParentQuery funktioniert nicht?
Laufen elasticsearch 2.4, kann ich keine Informationen darüber finden. Oder könnte es sein, dass es ein Fehler ist? https://www.elastic.co/guide/en/elasticsearch/reference/2.4/search-request-named-queries-and-filters.html
Ausgabe
parent
outerBool
// "innerBool" and "term" should also be here?
JSON Suchabfrage
{
"query": {
"bool": {
"must": {
"has_parent": {
"query": {
"bool": {
"should": {
"term": {
"value": {
"value": "1",
"_name": "term"
}
}
},
"_name": "innerBool"
}
},
"parent_type": "branch",
"_name": "parent"
}
},
"_name": "outerBool"
}
}
}
Und der Test:
client.admin().indices().create(new CreateIndexRequest("my_index")).actionGet();
String employee =
IOUtils.toString(this.getClass().getClassLoader().getResourceAsStream("employeeMapping.json"));
client.admin().indices().preparePutMapping("my_index")
.setType("employee").setSource(employee).execute().actionGet();
String branch = IOUtils.toString(this.getClass().getClassLoader().getResourceAsStream("branchMapping.json"));
client.admin().indices().preparePutMapping("my_index").setType("branch").setSource(branch).execute()
.actionGet();
String parentId = "1";
client.prepareIndex("my_index", "branch", parentId)
.setSource(new HashMap<String, Object>() {{
put("value", "1");
put("value2", "2");
}}).execute().actionGet();
client.prepareIndex("my_index", "employee", parentId)
.setSource(new HashMap<String, Object>() {{
put("id", "1");
}}).setParent(parentId).execute().actionGet();
Thread.sleep(1000);
SearchRequestBuilder searchRequestBuilder = client.prepareSearch("my_index").setTypes("employee").setQuery(
QueryBuilders.boolQuery().must(
QueryBuilders.hasParentQuery("branch",
QueryBuilders.boolQuery()
.should(QueryBuilders.termQuery("value", "1").queryName("term")).queryName("innerBool")
).queryName("parent")
).queryName("outerBool")
);
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
Arrays.stream(searchResponse.getHits().getHits()[0].getMatchedQueries()).forEach(q ->
System.out.println(q)
);
branchMapping.json
{
"properties": {}
}
employeeMapping.json
{
"_parent": {
"type": "branch"
}
}