elasticsearch - Elasticsearch对子孙的内在打击

标签 elasticsearch

我对新的inner_hits功能有些麻烦。
在 parent / child 上使用时,它可以工作,但是如果我尝试在孙子上使用它,则似乎不起作用。

这是我的 map

{
    "test": {
        "template": "test",
        "settings": {
            "index": {
                "number_of_replicas": 0
            }
        },
        "mappings": {
            "parents": {
                "dynamic": "strict",
                "_routing": {
                    "required": true
                },
                "properties": {
                    "parent_value": {
                        "type": "string"
                    }
                }
            },
            "children": {
                "dynamic": "strict",
                "_routing": {
                    "required": true
                },
                "_parent": {
                    "type": "parents"
                },
                "properties": {
                    "parent_id": {
                        "type": "string",
                        "index": "not_analyzed"
                    },
                    "child_value": {
                        "type": "string"
                    }
                }
            },
            "grandchildren": {
                "dynamic": "strict",
                "_routing": {
                    "required": true
                },
                "_parent": {
                    "type": "children"
                },
                "properties": {
                    "children_id": {
                        "type": "string",
                        "index": "not_analyzed"
                    }
                }
            }
        }
    }
}

我通过Sense插入数据
PUT test/parents/parent_id?routing=1
{
    "parent_value": "PARENT VALUE"
}

PUT test/children/child_id?routing=1&parent=parent_id
{
    "parent_id": "parent_id",
    "child_value": "CHILD VALUE"
}

PUT test/grandchildren/grandchild_id?routing=1&parent=child_id
{
    "children_id": "child_id"
}

这很完美
GET test/children/_search?routing=1
{
   "post_filter": {
      "bool": {
         "must": [
            {
               "has_parent": {
                  "parent_type": "parents",
                  "filter": {
                     "bool": {
                        "must": [
                           {
                              "ids": {
                                  "values": ["parent_id"]
                              }
                           }
                        ]
                     }
                  },
                  "inner_hits": {
                  }
               }
            }
         ]
      }
   }
}

好极了!

但是,如果我尝试此操作,它将找到一个文档,但是inner_hits为空。
GET test/grandchildren/_search?routing=1
{
   "post_filter": {
      "bool": {
         "must": [
            {
               "has_parent": {
                  "parent_type": "children",
                  "filter": {
                     "bool": {
                        "must": [
                           {
                              "ids": {
                                  "values": ["child_id"]
                              }
                           }
                        ]
                     }
                  },
                  "inner_hits": {
                  }
               }
            }
         ]
      }
   }
}

我究竟做错了什么..?

最佳答案

这是一个已知的issue.workaround用于重复查询所有inner hits分支的级别:

curl -XGET "http://localhost:9200/_search" -d'
{
  "query": {
    "nested": {
      "path": "cars",
      "query": {
        "nested": {
          "path": "cars.manufacturers",
          "query": {
            "match": {
              "cars.manufacturers.country": "Japan"
            }
          }
        }
      }
    }
  },
  "inner_hits": {
    "cars": {
      "path": {
        "cars": {
          "query": {
            "nested": {
              "path": "cars.manufacturers",
              "query": {
                "match": {
                  "cars.manufacturers.country": "Japan"
                }
              }
            }
          },
          "inner_hits": {
            "manufacturers": {
              "path": {
                "cars.manufacturers": {
                  "query": {
                    "match": {
                      "cars.manufacturers.country": "Japan"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}'

关于elasticsearch - Elasticsearch对子孙的内在打击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29361395/

相关文章:

java - ElasticSearch - 使用 Java HighLevel HTTP 客户端删除索引

elasticsearch - spring data elasticsearch-查询-全文搜索

elasticsearch - 带有标准分析器和编号的Elasticsearch完成建议

java - Java中的Elasticsearch条件评分

node.js - StatusCodeError:[not_x_content_exception]压缩器检测只能在某些xcontent字节或压缩的xcontent字节上调用

python-2.7 - 滚动请求中的 "batch of results"大小是多少

.net - 将Elasticsearch更新到7.0后的异常

python - 如何滚动弹性查询结果,python

elasticsearch - 如何在Logstash的tar包中增加LS_HEAP_SIZE

java - Elasticsearch 中的 JSON 后编码