elasticsearch has\u child和has\u parent未返回结果,elasticsearch,kibana,elasticsearch-7,elasticsearch,Kibana,Elasticsearch 7" /> elasticsearch has\u child和has\u parent未返回结果,elasticsearch,kibana,elasticsearch-7,elasticsearch,Kibana,Elasticsearch 7" />

elasticsearch has\u child和has\u parent未返回结果

elasticsearch has\u child和has\u parent未返回结果,elasticsearch,kibana,elasticsearch-7,elasticsearch,Kibana,Elasticsearch 7,在粘贴问题之前,我浏览了以下链接 我创建了一个简单的映射,将text\u doc作为父对象,将flag\u doc作为子对象 { "doc_index_ap3" : { "mappings" : { "properties" : { "domain" : { "type" : "keyword"

在粘贴问题之前,我浏览了以下链接

我创建了一个简单的映射,将
text\u doc
作为父对象,将
flag\u doc
作为子对象

{
  "doc_index_ap3" : {
    "mappings" : {
      "properties" : {
        "domain" : {
          "type" : "keyword"
        },
        "email_text" : {
          "type" : "text"
        },
        "id" : {
          "type" : "keyword"
        },
        "my_join_field" : {
          "type" : "join",
          "eager_global_ordinals" : true,
          "relations" : {
            "text_doc" : "flag_doc"
          }
        }
      }
    }
  }
}
具有
parent\u id
的查询工作正常并按预期返回1个文档

GET doc_index_ap3/_search
{
  "query": {
      "parent_id": {
        "type": "flag_doc",
        "id":"f0d2cb3c-bf4b-11eb-9f67-93a282921115"
      }
  }
}
但是下面的查询都不会返回任何结果

GET doc_index_ap3/_search
{
  "query": {
    "has_parent": {
      "parent_type": "text_doc",
      "query": {
        "match_all": {
        }
      }
    }
  }
}

GET doc_index_ap3/_search
{
  "query": {
    "has_child": {
      "type": "flag_doc",
      "query": {
        "match_all": {}
      }
    }
  }
}

为父文档和子文档编制索引的方式一定有问题。请参阅此官方文档,了解更多信息

使用与上述问题相同的索引映射添加一个工作示例

文本文档上下文中的父文档

PUT /index-name/_doc/1

{
  "domain": "ab",
  "email_text": "ab",
  "id": "ab",
  "my_join_field": {
    "name": "text_doc"
  }
}
PUT /index-name/_doc/2?routing=1&refresh



 {
  "domain": "cs",
  "email_text": "cs",
  "id": "cs",
  "my_join_field": {
    "name": "flag_doc",
    "parent": "1"
  }
}
子文档

PUT /index-name/_doc/1

{
  "domain": "ab",
  "email_text": "ab",
  "id": "ab",
  "my_join_field": {
    "name": "text_doc"
  }
}
PUT /index-name/_doc/2?routing=1&refresh



 {
  "domain": "cs",
  "email_text": "cs",
  "id": "cs",
  "my_join_field": {
    "name": "flag_doc",
    "parent": "1"
  }
}
搜索查询:

{
  "query": {
    "has_parent": {
      "parent_type": "text_doc",
      "query": {
        "match_all": {
        }
      }
    }
  }
}
"hits": [
      {
        "_index": "67731507",
        "_type": "_doc",
        "_id": "2",
        "_score": 1.0,
        "_routing": "1",
        "_source": {
          "domain": "cs",
          "email_text": "cs",
          "id": "cs",
          "my_join_field": {
            "name": "flag_doc",
            "parent": "1"
          }
        }
      }
    ]
{
  "query": {
    "has_child": {
      "type": "flag_doc",
      "query": {
        "match_all": {}
      }
    }
  }
}
"hits": [
      {
        "_index": "67731507",
        "_type": "_doc",
        "_id": "1",
        "_score": 1.0,
        "_source": {
          "domain": "ab",
          "email_text": "ab",
          "id": "ab",
          "my_join_field": {
            "name": "text_doc"
          }
        }
      }
    ]
搜索结果:

{
  "query": {
    "has_parent": {
      "parent_type": "text_doc",
      "query": {
        "match_all": {
        }
      }
    }
  }
}
"hits": [
      {
        "_index": "67731507",
        "_type": "_doc",
        "_id": "2",
        "_score": 1.0,
        "_routing": "1",
        "_source": {
          "domain": "cs",
          "email_text": "cs",
          "id": "cs",
          "my_join_field": {
            "name": "flag_doc",
            "parent": "1"
          }
        }
      }
    ]
{
  "query": {
    "has_child": {
      "type": "flag_doc",
      "query": {
        "match_all": {}
      }
    }
  }
}
"hits": [
      {
        "_index": "67731507",
        "_type": "_doc",
        "_id": "1",
        "_score": 1.0,
        "_source": {
          "domain": "ab",
          "email_text": "ab",
          "id": "ab",
          "my_join_field": {
            "name": "text_doc"
          }
        }
      }
    ]

搜索查询:

{
  "query": {
    "has_parent": {
      "parent_type": "text_doc",
      "query": {
        "match_all": {
        }
      }
    }
  }
}
"hits": [
      {
        "_index": "67731507",
        "_type": "_doc",
        "_id": "2",
        "_score": 1.0,
        "_routing": "1",
        "_source": {
          "domain": "cs",
          "email_text": "cs",
          "id": "cs",
          "my_join_field": {
            "name": "flag_doc",
            "parent": "1"
          }
        }
      }
    ]
{
  "query": {
    "has_child": {
      "type": "flag_doc",
      "query": {
        "match_all": {}
      }
    }
  }
}
"hits": [
      {
        "_index": "67731507",
        "_type": "_doc",
        "_id": "1",
        "_score": 1.0,
        "_source": {
          "domain": "ab",
          "email_text": "ab",
          "id": "ab",
          "my_join_field": {
            "name": "text_doc"
          }
        }
      }
    ]
搜索结果:

{
  "query": {
    "has_parent": {
      "parent_type": "text_doc",
      "query": {
        "match_all": {
        }
      }
    }
  }
}
"hits": [
      {
        "_index": "67731507",
        "_type": "_doc",
        "_id": "2",
        "_score": 1.0,
        "_routing": "1",
        "_source": {
          "domain": "cs",
          "email_text": "cs",
          "id": "cs",
          "my_join_field": {
            "name": "flag_doc",
            "parent": "1"
          }
        }
      }
    ]
{
  "query": {
    "has_child": {
      "type": "flag_doc",
      "query": {
        "match_all": {}
      }
    }
  }
}
"hits": [
      {
        "_index": "67731507",
        "_type": "_doc",
        "_id": "1",
        "_score": 1.0,
        "_source": {
          "domain": "ab",
          "email_text": "ab",
          "id": "ab",
          "my_join_field": {
            "name": "text_doc"
          }
        }
      }
    ]

嘿是的,我正在使用python脚本为文档编制索引。父文档的结构是`父文档={“id”:“1”,“电子邮件文本”:“'my_join_field':{“name”:“text_doc”}`和子文档的结构`子文档={“id”:“child_1”,“domain”:“abc.com”,“routing”:“'my_join_field':{“name”:“flag_doc”,“parent”:“1}”“我用父文档的
id
填充
路由
。哦,实际上,我刚刚注意到,在查询子文档索引时,您使用了
“父文档”:“1”
,它是父文档的
\u id
,而不是
id
。让我更新我的脚本并再次尝试,谢谢!