Home > database >  Elasticsearch mappings ignored
Elasticsearch mappings ignored

Time:09-17

Hello look like mappings don't work for me, so i had tried to delete index and re-index but always getting same results. Here is how mappings look and response from GET search endpoint. So entry_id field is mapped as integer, but returned as a string.

localhost:9200/entries-vlatest/_mapping

{
    "entries-v1631182320": {
        "mappings": {
            "_doc": {
                "dynamic": "false",
                "properties": {
                    "entry_id": {
                        "type": "integer"
                    }
                }
            }
        }
    }
}

Response from get Search localhost:9200/entries-vlatest/_search

  "took": 4,
    "timed_out": false,
    "_shards": {
        "total": 2,
        "successful": 2,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 1,
        "max_score": 1.0,
        "hits": [
            {
                "_index": "entries-v1631182320",
                "_type": "_doc",
                "_id": "15",
                "_score": 1.0,
                "_source": {
                    "entry_id": "15",
               
                }
            }
        ]
    }
}

So i have tried to delete index and re-index with

POST localhost:9200/_reindex

    {
      "source": {
        "index": "entries-v1631182320"
      },
      "dest": {
        "index": "new_index"
      }
    }
Result:
    {
        "took": 257,
        "timed_out": false,
        "total": 1,
        "updated": 0,
        "created": 1,
        "deleted": 0,
        "batches": 1,
        "version_conflicts": 0,
        "noops": 0,
        "retries": {
            "bulk": 0,
            "search": 0
        },
        "throttled_millis": 0,
        "requests_per_second": -1.0,
        "throttled_until_millis": 0,
        "failures": []
    }

But again getting same results, when i search re-indexed GET localhost:9200/new_index/_search

{
    "took": 2,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 1,
        "max_score": 1.0,
        "hits": [
            {
                "_index": "novi",
                "_type": "_doc",
                "_id": "15",
                "_score": 1.0,
                "_source": {
                    "entry_id": "15"
                   
                }
            }
        ]
    }
}

Any idea how to solve this?

CodePudding user response:

It is working correctly. You're sending your source document with entry_id as a string and Elasticsearch will not modify that source document, but store it as is.

However, the entry_id field will be indexed and stored as described in your mapping, i.e. as an integer

If you want to "see" an integer, then add the value as an integer in your source document. But in the end it doesn't make any difference, that value will be seen and handled as specified in your mapping, i.e. as an integer, even though you sent it as a string in your document.

  • Related