Search code examples
elasticsearch

Elasticsearch store field vs _source


Using Elasticsearch 1.4.3

I'm building a sort of "reporting" system. And the client can pick and chose which fields they want returned in their result.

In 90% of the cases the client will never pick all the fields, so I figured I can disable _source field in my mapping to save space. But then I learned that

GET myIndex/myType/_search/
{
    "fields": ["field1", "field2"]
    ...
}

Does not return the fields.

So I assume I have to then use "store": true for each field. From what I read this will be faster for searches, but I guess space wise it will be the same as _source or we still save space?


Solution

  • The _source field stores the JSON you send to Elasticsearch and you can choose to only return certain fields if needed, which is perfect for your use case. I have never heard that the stored fields will be faster for searches. The _source field could be bigger on disk space, but if you have to store every field there is no need to use stored fields over the _source field. If you do disable the source field it will mean:

    • You won’t be able to do partial updates
    • You won’t be able to re-index your data from the JSON in your Elasticsearch cluster, you’ll have to re-index from the data source (which is usually a lot slower).