如何在多代设置中查询针对祖父母的inner_hits

时间:2015-11-04 22:14:37

标签: elasticsearch

所以我根据这个设置了我的Elasticsearch商店:https://www.elastic.co/guide/en/elasticsearch/guide/current/grandparents.html

PUT /company
{
  "mappings": {
    "country": {},
    "branch": {
      "_parent": {
        "type": "country" 
      }
    },
    "employee": {
      "_parent": {
        "type": "branch" 
      }
    }
  }
}
POST /company/country/_bulk
{ "index": { "_id": "uk" }}
{ "name": "UK" }
{ "index": { "_id": "france" }}
{ "name": "France" }

POST /company/branch/_bulk
{ "index": { "_id": "london", "parent": "uk" }}
{ "name": "London Westmintster" }
{ "index": { "_id": "liverpool", "parent": "uk" }}
{ "name": "Liverpool Central" }
{ "index": { "_id": "paris", "parent": "france" }}
{ "name": "Champs Élysées" }

PUT /company/employee/1?parent=london&routing=uk 
{
  "name":  "Alice Smith",
  "dob":   "1970-10-24",
  "hobby": "hiking"
}

此查询正常工作并按预期返回Alice,但没有inner_hits:

POST /company/employee/_search
{
    "query": {
        "has_parent": {
            "type": "branch",
            "query": {
                "term": {"_id": "london"}
            },
            "inner_hits": {}
        }
    }
}

但是这个查询不会返回任何inner_hits:

POST /company/employee/_search
{
    "query": {
        "has_parent": {
            "type": "branch",
            "query": {
                "has_parent": {
                    "type": "country",
                    "query": {
                        "term": {"_id": "uk"}
                    }
                },
                "inner_hits": {}
            }
        }
    }
}

我以为它会归还爱丽丝,但事实并非如此。如何查找国家/地区为uk的所有员工?

请注意,elastic.co上的示例查询也不返回任何inner_hits。这是查询:

GET /company/country/_search
{
  "query": {
    "has_child": {
      "type": "branch",
      "query": {
        "has_child": {
          "type": "employee",
          "query": {
            "match": {
              "hobby": "hiking"
            }
          },
          "inner_hits": {}
        }
      }
    }
  }
}

我没有内心命中率。

1 个答案:

答案 0 :(得分:1)

这是目前杰出的inner_hits

您可以在此处添加问题:https://github.com/elastic/elasticsearch/issues/11118