How get the document field when disable the _source?

Hi,

I'm trying to disable _source as in my case the updated and reindex are unnecessary feature.
The issue is I cannot get any field when the _source is diabled.

I created a index like:
curl -XPUT http://localhost:9200/test1 -d '{"mappings":{"test":{"_source":{"enabled": false}}}}'
{"acknowledged":true}
and put a document in:
curl -XPUT http://localhost:9200/test1/test/1 -d '{"f1":"1111","f2":"222"}'
{"_index":"test1","_type":"test","_id":"1","_version":1,"created":true}

when try to get this document only the meta field returned
curl -XGET http://localhost:9200/test1/test/1
{"_index":"test1","_type":"test","_id":"1","_version":1,"found":true}

Is there something wrong?

Thanks

1 Like

There is nothing wrong, Elasticsearch is working as expected. The field values are stored in the _source field and when you get a document this is what is returned. If you disable _source no fields will be stored and therefore will not be shown on a get request. You need to re-enable your _source field. Disabling the _source field is generally not recommend as is only useful in instances where you never need the stored values of the fields.

1 Like

Hi Colin

Thanks for your answers. Seems I need to manally controle which field need to be store if the _source was disabled, right?

Thanks a lot.

Correct, but why not store _source?

For insert performance concern. As elasticsearch generate lots of extra inform far beyond the docment itself, I'd like to disable them which feature I didn't need.
But seems the _source is the one I need.