如何对ES 6.0中的示例执行has_child查询

时间:2018-02-21 05:46:08

标签: elasticsearch elasticsearch-6

Here是有关弹性搜索中join类型的示例。我有插图映射,父母和孩子:

PUT my_index
{
  "mappings": {
    "doc": {
      "properties": {
        "my_join_field": {
          "type": "join",
          "relations": {
            "question": "answer"
          }
        }
      }
    }
  }
}

PUT my_index/doc/1?refresh
{
  "text": "This is a question",
  "my_join_field": {
    "name": "question"
  }
}

PUT my_index/doc/2?refresh
{
  "text": "This is a another question",
  "my_join_field": {
    "name": "question"
  }
}

PUT my_index/doc/1?refresh
{
  "text": "This is a question",
  "my_join_field": "question"
}

PUT my_index/doc/2?refresh
{
  "text": "This is another question",
  "my_join_field": "question"
}

现在我正在努力寻找孩子的父母:

GET /my_index/doc/_search
{
  "query": {
    "has_child": {
      "type": "my_join_field",
      "query": {
        "match" : {
          "text": "question"
        }
      },
      "ignore_unmapped": true
    }
  },
  "highlight" : {
    "fields" : {
      "content" : {}
    }
  }
}

我没有结果。 :(> :(

首先应该是type个字段?他们被告知已删除types 其次,我必须添加ignore_unmapped(查看here),但仍然没有结果

那么如何通过has_child查询弹性搜索示例中的数据来查找父项?

1 个答案:

答案 0 :(得分:0)

查看11_parent_child.yml文件。它包含父,子的索引,并执行子项查询。它是yaml,但我认为转换为json是显而易见的。