简体   繁体   English

Elasticsearch:将映射字段类型 ID 从 long 更新为 string

[英]Elasticsearch: Update mapping field type ID from long to string

I changed the elasticsearch mapping field type from:我将 elasticsearch 映射字段类型从:

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

to

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

After that I did the following steps:之后我做了以下步骤:

  1. Create the index with new mapping使用新映射创建索引
  2. Reindex the mapping to the new index将映射重新索引到新索引

After the mapping update my previous query filter doesn't work anymore and I have no results:映射更新后,我之前的查询过滤器不再起作用,并且没有结果:

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

If I check with this query the result is what I expect:如果我检查这个查询结果是我所期望的:

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

I would appreciate if somebody have some idea why after the field type change the query is no longer working.如果有人知道为什么在字段类型更改后查询不再工作,我将不胜感激。

Thanks!谢谢!

The problem in the query was with ID filter.查询中的问题是 ID 过滤器。 The query works correctly changing the filter from:查询工作正常,将过滤器更改为:

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

in:在:

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

I'm still a beginner with elasticsearch to figure out why the mapping change broke the query although I did the reindex, but "_id" fixed my query.我仍然是 Elasticsearch 的初学者,想弄清楚为什么虽然我进行了重新索引,但映射更改破坏了查询,但“_id”修复了我的查询。

You can find more informations in the : elasticsearch mapping reference documentation .您可以在: elasticsearch 映射参考文档中找到更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM