Reyela
Reyela

Reputation: 146

Elasticsearch: Update mapping field type ID from long to string

I changed the elasticsearch mapping field type from:

    "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!

Upvotes: 2

Views: 1329

Answers (1)

Reyela
Reyela

Reputation: 146

The problem in the query was with ID filter. 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.

You can find more informations in the : elasticsearch mapping reference documentation.

Upvotes: 1

Related Questions