Home > other >  Elasticsearch cannot index array of integers
Elasticsearch cannot index array of integers

Time:04-22

Given mapping:

{
    "mappings": {
        "properties": {
            "user_ids": {"type": "integer"}
        }
    }
}

Observations:

  • Index {"user_ids": 1}, and data will show up correctly
  • Index {"user_ids": "x"}, and error is thrown failed to parse field [user_ids] of type [integer] in document, indicating that mapping is working correctly
  • However, indexing {"user_ids": [1]} just clears the field, without throwing error.

Question:

  • Why does this happen and how can I index arrays of integers?

Extra:

  • I removed all settings config, doesn't change anything
  • I tried keyword type, doesn't change anything
  • If relevant, I use latest opensearch-py

CodePudding user response:

It's not clear what do you mean by clear the field, also indexing array of integers works perfectly fine as shown in below example, hope you are following same requests.


put <index-name>/_doc/1
{
    "user_ids": [
        1,2,3
    ]
}

And get API returns, all the integers in the array.

GET <index-name>/_doc/1
    "_source": {
        "user_ids": [
            1,
            2,
            3
        ]
    }
}

CodePudding user response:

Turns out it's my own error: I was using elasticsearch-head for quick checking of values, and they don't support displaying of array values :/ Once I double checked with queries, they came back correct.

  • Related