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