【问题标题】:Elasticsearch type and attribute name inferenceElasticsearch 类型和属性名称推断
【发布时间】:2016-06-17 22:02:51
【问题描述】:

我正在使用 Elasticsearch 1.7 并遇到以下问题: 当属性被命名为索引的类型时,我无法在不涉及类型名称的情况下过滤属性。我最好给你举个例子:

索引:

curl -XPUT "http://localhost:9200/myindex/ingredient/1" -d'
{
  "name": "salad"
}'

curl -XPUT "http://localhost:9200/myindex/product/1" -d'
{
  "name": "sandwich",
  "ingredient": {
    "name": "salad"
  }
}'

过滤:

curl -XGET "http://localhost:9200/myindex/_search" -d'
{
  "query": {
    "term": {
      "ingredient.name": "salad"
    }
  }
}'

回复:

{
  "_index": "myindex",
  "_type": "ingredient",
  "_id": "1",
  "_score": 1,
  "_source": {
    "name": "salad"
  }
}

问题: 响应是类型成分。我想获得具有属性成分.name="沙拉"的对象。 Elasticsearch 将属性名称理解为一种类型。当我过滤 product.ingredient.name="salad" 时,我得到了预期的产品。

我无法获得我想要过滤的东西的类型,有没有另一种说法,我的意思是属性名称,而不是类型?

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    这是 elasticsearch:1.x 中的一个已知问题,其中有多种方法可以引用导致歧义的一个字段。

    除了

    ,没有更好的办法了

    a) 如 OP 中所述,显式添加 type

    b) 将搜索限制在特定的type
    http://localhost:9200/myindex/<type>/_search

    这在 elasticsearch 2.x 中已修复。来自 elastica 的 blog 对此有很好的解释。

    【讨论】:

    • 感谢您清除它。我想,那我得更新了。
    猜你喜欢
    • 2022-08-14
    • 1970-01-01
    • 1970-01-01
    • 2019-02-02
    • 1970-01-01
    • 1970-01-01
    • 2016-04-20
    • 1970-01-01
    • 2022-10-06
    相关资源
    最近更新 更多