【问题标题】:Elasticsearch - Query by parent idElasticsearch - 按父 ID 查询
【发布时间】:2015-04-23 18:52:29
【问题描述】:

我有三种文档类型,具有以下与父/子关系的映射。我省略了其他属性,因为我认为它们与问题无关。

   "mappings": {
     "Parent": {            
        },
     "Child": {
        "_parent": {
           "type": "Parent"
        },
        "_routing": {
           "required": true
        }             
     },
     "GrandChild": {
        "_parent": {
           "type": "Child"
        },
        "_routing": {
           "required": true
        }             
     }
  }

我正在使用 java api 将文档插入索引。在索引文档之前,需要删除具有相同 id 的现有文档以避免重复。 Parent's Id 和 Child's Id 存储在外部。首先,所有“GrandChild”文档都使用对其父 ID(在本例中为“Child”类型的 ID)进行术语查询来删除。没有错误,但“GrandChild”文档没有被删除。

通过使用 chrome 插件 Sense 运行以下术语查询,我发现问题出在术语查询中。它不返回点击数。 Parent、Child 和 GrandChild 具有相同的路由值,设置为 Parent 的 id。这是我试过的查询。

POST /myindex/GrandChild/_search?routing=DFC0E8CD59EBC00EC2DDC9A0FF5D1F2DB272B2449680824CCE60B6864568D498
{
    "query" : {
        "term" : { "_parent" : "//id/of/doc/of/type/Child" }
    }
}

当我尝试使用其父 ID 搜索“子”文档时,它可以工作。我使用以下查询得到一个“孩子”。

POST /myindex/Child/_search?routing=DFC0E8CD59EBC00EC2DDC9A0FF5D1F2DB272B2449680824CCE60B6864568D498
{
    "query" : {
        "term" : { "_parent" : "DFC0E8CD59EBC00EC2DDC9A0FF5D1F2DB272B2449680824CCE60B6864568D498" }
    }
} 

我在“孙子”搜索中可能做错了什么?

感谢任何帮助。谢谢。

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    从 elasticsearch 邮件列表中获得了问题的答案 https://groups.google.com/forum/#!topic/elasticsearch/d_aZejNMBD8

    这里有一个未解决的问题: https://github.com/elasticsearch/elasticsearch/issues/5399

    编辑: 如 Github 问题所示,执行查询的方法是在 ID 前面加上父类型:

    POST /myindex/GrandChild/_search?routing=DFC0E8CD59EBC00EC2DDC9A0FF5D1F2DB272B2449680824CCE60B6864568D498    
    {
        "query" : {
            "term" : { "_parent" : "Child#//id/of/doc/of/type/Child" }
        }
    }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-22
    • 1970-01-01
    • 1970-01-01
    • 2020-11-16
    • 2018-06-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多