0
彈性文檔聲明可以在查詢中使用_parent字段(請參閱https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-parent-field.html)。ElasticSearch _parent查詢
但是,我一直無法讓它工作。下面是簡單的測試:
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"
}
驗證該員工有_parent場:
GET /company/employee/_search
{
"query": {
"match_all": {}
}
}
回報
{
"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"
}
}
]
}
}
但以下幾點:
GET /company/employee/_search
{
"query": {
"term": {
"_parent":"london"
}
}
}
回報:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
使用「has_parent」工作,但爲什麼不使用_parent工作,如文檔中所述。
下面是使用has_parent的作品查詢:
GET /company/employee/_search
{
"query": {
"has_parent": {
"parent_type":"branch",
"query":{
"match_all": {}
}
}
}
}
我缺少什麼?使用ElasticSearch 5.0.2。
有沒有這樣的運氣? – Val