【问题标题】:Elasticsearch: Update mapping field type ID from long to stringElasticsearch:将映射字段类型 ID 从长更新为字符串
【发布时间】:2015-04-24 21:46:51
【问题描述】:

我将 elasticsearch 映射字段类型从:

    "articles": {
        "properties": {
          "id": {
              "type": "long"
          }}}

     "articles": {
        "properties": {
           "id": {
              "type": "string",
              "index": "not_analyzed"
           }

之后我做了以下步骤:

  1. 使用新映射创建索引
  2. 重新索引映射到新索引

映射更新后,我之前的查询过滤器不再起作用,并且没有结果:

GET /art/_search
{
    "query": {
    "filtered": {
         "query": {
        "match_all": {}
        },
         "filter": {
            "bool": {
               "must": [
                      {
                      "type": {
                      "value": "articles"
                     }
                  },
                  {
                      "term": {
                      "id": "123467679"
                     }
                  }
               ]
            }
         }
      }
   },
   "size": 1,
   "sort": [
      {
          "_score": "desc"
      }
   ]
}

如果我检查这个查询,结果就是我所期望的:

GET /art/articles/_search
{
  "query": {
    "match_all": {}
  }
}

如果有人知道为什么在字段类型更改后查询不再起作用,我将不胜感激。

谢谢!

【问题讨论】:

    标签: indexing elasticsearch mapping filtering


    【解决方案1】:

    查询中的问题在于 ID 过滤器。 查询正常工作,将过滤器更改为:

    "term": {
             "id": "123467679"
            }
    

    在:

    "term": {
             "_id": "123467679"
            }
    

    我仍然是 elasticsearch 的初学者,想弄清楚为什么映射更改会破坏查询,尽管我进行了重新索引,但“_id”修复了我的查询。

    您可以在以下位置找到更多信息: elasticsearch mapping reference documentation.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-13
      • 1970-01-01
      • 2017-07-28
      • 2016-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多