What is the difference between nested objects and the object type in Elasticsearch?

Answer

In Elasticsearch, when you index an array of objects with the object type (the default), Elasticsearch flattens the inner objects — their field values are all merged into flat arrays. This means cross-field relationships between inner object properties are lost, leading to incorrect query results. For example, if you have products with multiple prices per region, a query "price > 100 AND region = US" might incorrectly match a document where one object has price > 100 but a different object has region = US. The nested type solves this by storing each inner object as a separate hidden Lucene document, preserving the relationship between fields. However, nested queries are slower and require the nested query wrapper.