docphilstone
docphilstone

Reputation: 91

Why is ElasticSearch putting strings in arrays?

I'm adding documents to an new index I created in elasticsearch (v7.15.1). I have a nested field I explicitly mapped:

curl -X PUT "localhost:9200/newIndex/_mapping?pretty" -H 'Content-Type: application/json' -d'
{
    "properties": {
        "authors": {
            "type": "nested"
        }
    }
}
'

both properties under "authors" are strings. When adding documents to the index, each property under author is an array containing the string,

ex.

"author": ["John Smith"]

instead of

"author": "John Smith"

I've tried explicitly mapping the nested field as well as text, and I got the same result. Is there anyway to prevent this?

Upvotes: 0

Views: 212

Answers (1)

Vakhtang
Vakhtang

Reputation: 431

You don't need nested type. The nested field used for array of the Objects, not for array of the Strings. So you can use mapping like:

{
    "properties": {
        "authors": {
            "type": "keyword"
        }
    }
}

Or if you want to search only first name, you can use "type" : "text", or both of them with multifield '

Upvotes: 1

Related Questions