Elastische Dokumentation besagt, dass man das _parent-Feld in einer Abfrage verwenden kann (siehe https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-parent-field.html).ElasticSearch _parent Abfrage
Allerdings konnte ich es nicht zur Arbeit bringen. Hier ist die einfache Test:
PUT /company
{
"mappings": {
"branch": {},
"employee": {
"_parent": {
"type": "branch"
}
}
}
}
POST /company/branch/_bulk
{ "index": { "_id": "london" }}
{ "name": "London Westminster", "city": "London", "country": "UK" }
{ "index": { "_id": "liverpool" }}
{ "name": "Liverpool Central", "city": "Liverpool", "country": "UK" }
{ "index": { "_id": "paris" }}
{ "name": "Champs Élysées", "city": "Paris", "country": "France" }
PUT /company/employee/1?parent=london
{
"name": "Alice Smith",
"dob": "1970-10-24",
"hobby": "hiking"
}
Überprüfen, dass die Mitarbeiter haben ein _parent Feld:
GET /company/employee/_search
{
"query": {
"match_all": {}
}
}
kehrt
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "company",
"_type": "employee",
"_id": "1",
"_score": 1,
"_routing": "london",
"_parent": "london",
"_source": {
"name": "Alice Smith",
"dob": "1970-10-24",
"hobby": "hiking"
}
}
]
}
}
Aber die folgenden:
GET /company/employee/_search
{
"query": {
"term": {
"_parent":"london"
}
}
}
kehrt:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
Die Verwendung von "has_parent" funktioniert, aber warum nicht _parent funktioniert, wie in den Dokumenten angegeben.
Hier ist die Abfrage has_parent verwenden, das funktioniert:
GET /company/employee/_search
{
"query": {
"has_parent": {
"parent_type":"branch",
"query":{
"match_all": {}
}
}
}
}
Was bin ich? Verwenden von ElasticSearch 5.0.2.
Haben Sie Glück dabei? – Val