0

I am still learning elasticsearch. I wanted to know, if there is a way where the type of the value of a particular key is not fixed, can we still index it?

for example firstName can be "xyz" and it can also be an object in another document of the same type, and there is a huge combination of such fields which can all have string or object as the value, so it is not like I can isolate the string one and the object one in different indexes.

Thanks

1 Answer 1

1

Elasticsearch doesn't support this.

Elasticsearch does have features to "auto detect" what the type for a field should be. However, the first time it sees a field, it will make its guess, and then every subsequent record that has that field will have to match.

In your case, if a record where firstName was a string was indexed first, then all records where firstName is an object will throw an error when you try to index them in Elasticsearch. If an object was indexed first, all the records where firstName is a string would fail.

Elasticsearch is designed to help you get started quickly, but ultimately there's no shortcut and you will have to:

  • Design a schema that tells Elasticsearch good settings to use for each field
  • Do the work in your code that imports records into Elasticsearch to make decisions about how you want to import them
Sign up to request clarification or add additional context in comments.

1 Comment

These are NoSQL schemas, and I believe I will have to run it through a value transformer to maintain the same type for each field.

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.