0

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?

1 Answer 1

1

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 '

Sign up to request clarification or add additional context in comments.

2 Comments

Sorry, I did not explain fully, the authors field is an array of objects. Each object represents a single author with multiple fields. It is the values of the author fields that are strings, but being uploaded as strings within arrays.
Am i understud right, that your mapping supposed to be like: { "properties": { "authors": { "type": "nested", "properties":{ "name" :{ "type": "keyword" }, "user" :{ "type": "keyword" } } } } } Could you share the data example?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.