首页 文章

ElasticSearch在“fields”中指定时忽略名为'tags'的字段

提问于
浏览
0

我有一个搜索索引 products ,包含一个名为 tags 的字段,这是一个数组 . 当我不在查询中添加 fields 部分时,标签值会显示在结果中,但是当我这样做时,结果中会出现's just ignored outright, and doesn',如下所示 .

$ curl -XPOST 'http://localhost:9200/products/_search?pretty' -d '{  "query": {"match_all": {} }, "fields": ["tags", "id", "slug"], "size": 2}'
{
  "took" : 4,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 321826,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "products",
      "_type" : "products",
      "_id" : "39969794",
      "_score" : 1.0,
      "fields" : {
        "id" : [ "39969794" ],
        "slug" : [ "slug-39969794" ]
      }
    }, {
      "_index" : "products",
      "_type" : "products",
      "_id" : "21296413",
      "_score" : 1.0,
      "fields" : {
        "id" : [ "21296413" ],
        "slug" : [ "slug-21296413" ]
      }
    } ]
  }
}

这有什么理由或已知问题吗? tags 是ElasticSearch的某种保留字吗?

我正在使用ES版本1.1.2(Lucene 4.7) .

1 回答

  • 1

    tags 不是ES保留字 . 所以这不是你的问题 .

    您的标签是原子类型(数字,字符串还是布尔值)的数组?或者它是一个对象数组?

    fields 仅适用于叶节点 . 所以 "fields": ["tags"] 应该可以正常使用一个字符串数组,但它会因为一个 tag 对象数组而失败 .

相关问题