【问题标题】:ElasticSearch multifield not workingElasticSearch 多字段不起作用
【发布时间】:2015-07-08 20:35:57
【问题描述】:

在我的文档中,我有一个字段collaboration,我想在该字段上进行聚合查询。但是我也希望它可以全文搜索,所以我想我应该让它成为一个多字段。该字段可能如下所示:

...
"collaboration" : "CMS"
or
"collaboration" : ["ATLAS", "CMS"]
or
"collaboration" : "LHCb"
...

遵循此建议:ElasticSearch term aggregation 我将映射更改为:

"collaboration": {
    "type": "string",
    "fields": {
        "raw": {
            "type": "string",
            "index": "not_analyzed"
        }
    }
},

然后我运行一个查询:

POST /my_index/_search
{
   "aggs": {
        "collaboration": {
            "terms": {
                "field": "collaboration.raw"
            }
        }
    }
}

什么也得不到:

"hits": {
   "total": 5,
   "max_score": 1,
   "hits": [...]
},
"aggregations": {
   "collaboration": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets": []
   }
}

即使我尝试使用此字段进行搜索,它也不起作用:

POST /my_index/_search
{
    "query": {
        "query_string": {
            "query": "CMS",
            "fields": ["collaboration.raw"]
        }
    }
}

我是否应该以某种方式更改映射,因为该字段有时是一个列表,有时是一个字符串?我的研究发现arrays are supposed to be supported out of the box。有什么建议这里可能有什么问题吗?

【问题讨论】:

  • 在添加 .raw 之后,您是否从该索引中重新索引了所有文档?
  • 不!它现在有效,我不知道我怎么会错过这个。感谢您的帮助!

标签: elasticsearch aggregation


【解决方案1】:

感谢Andrei Stefan

更改映射后需要重新索引所有文档,小而痛苦的细节。

【讨论】:

    猜你喜欢
    • 2015-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-09
    • 1970-01-01
    相关资源
    最近更新 更多