enabled
editenabled
editElasticsearch tries to index all of the fields you give it, but sometimes you want to just store the field without indexing it. For instance, imagine that you are using Elasticsearch as a web session store. You may want to index the session ID and last update time, but you don’t need to query or run aggregations on the session data itself.
The enabled
setting, which can be applied only to the top-level mapping
definition and to object
fields, causes Elasticsearch to skip
parsing of the contents of the field entirely. The JSON can still be retrieved
from the _source
field, but it is not searchable or
stored in any other way:
resp = client.indices.create( index="my-index-000001", mappings={ "properties": { "user_id": { "type": "keyword" }, "last_updated": { "type": "date" }, "session_data": { "type": "object", "enabled": False } } }, ) print(resp) resp1 = client.index( index="my-index-000001", id="session_1", document={ "user_id": "kimchy", "session_data": { "arbitrary_object": { "some_array": [ "foo", "bar", { "baz": 2 } ] } }, "last_updated": "2015-12-06T18:20:22" }, ) print(resp1) resp2 = client.index( index="my-index-000001", id="session_2", document={ "user_id": "jpountz", "session_data": "none", "last_updated": "2015-12-06T18:22:13" }, ) print(resp2)
response = client.indices.create( index: 'my-index-000001', body: { mappings: { properties: { user_id: { type: 'keyword' }, last_updated: { type: 'date' }, session_data: { type: 'object', enabled: false } } } } ) puts response response = client.index( index: 'my-index-000001', id: 'session_1', body: { user_id: 'kimchy', session_data: { arbitrary_object: { some_array: [ 'foo', 'bar', { baz: 2 } ] } }, last_updated: '2015-12-06T18:20:22' } ) puts response response = client.index( index: 'my-index-000001', id: 'session_2', body: { user_id: 'jpountz', session_data: 'none', last_updated: '2015-12-06T18:22:13' } ) puts response
const response = await client.indices.create({ index: "my-index-000001", mappings: { properties: { user_id: { type: "keyword", }, last_updated: { type: "date", }, session_data: { type: "object", enabled: false, }, }, }, }); console.log(response); const response1 = await client.index({ index: "my-index-000001", id: "session_1", document: { user_id: "kimchy", session_data: { arbitrary_object: { some_array: [ "foo", "bar", { baz: 2, }, ], }, }, last_updated: "2015-12-06T18:20:22", }, }); console.log(response1); const response2 = await client.index({ index: "my-index-000001", id: "session_2", document: { user_id: "jpountz", session_data: "none", last_updated: "2015-12-06T18:22:13", }, }); console.log(response2);
PUT my-index-000001 { "mappings": { "properties": { "user_id": { "type": "keyword" }, "last_updated": { "type": "date" }, "session_data": { "type": "object", "enabled": false } } } } PUT my-index-000001/_doc/session_1 { "user_id": "kimchy", "session_data": { "arbitrary_object": { "some_array": [ "foo", "bar", { "baz": 2 } ] } }, "last_updated": "2015-12-06T18:20:22" } PUT my-index-000001/_doc/session_2 { "user_id": "jpountz", "session_data": "none", "last_updated": "2015-12-06T18:22:13" }
The |
|
Any arbitrary data can be passed to the |
|
The |
The entire mapping may be disabled as well, in which case the document is
stored in the _source
field, which means it can be
retrieved, but none of its contents are indexed in any way:
resp = client.indices.create( index="my-index-000001", mappings={ "enabled": False }, ) print(resp) resp1 = client.index( index="my-index-000001", id="session_1", document={ "user_id": "kimchy", "session_data": { "arbitrary_object": { "some_array": [ "foo", "bar", { "baz": 2 } ] } }, "last_updated": "2015-12-06T18:20:22" }, ) print(resp1) resp2 = client.get( index="my-index-000001", id="session_1", ) print(resp2) resp3 = client.indices.get_mapping( index="my-index-000001", ) print(resp3)
response = client.indices.create( index: 'my-index-000001', body: { mappings: { enabled: false } } ) puts response response = client.index( index: 'my-index-000001', id: 'session_1', body: { user_id: 'kimchy', session_data: { arbitrary_object: { some_array: [ 'foo', 'bar', { baz: 2 } ] } }, last_updated: '2015-12-06T18:20:22' } ) puts response response = client.get( index: 'my-index-000001', id: 'session_1' ) puts response response = client.indices.get_mapping( index: 'my-index-000001' ) puts response
const response = await client.indices.create({ index: "my-index-000001", mappings: { enabled: false, }, }); console.log(response); const response1 = await client.index({ index: "my-index-000001", id: "session_1", document: { user_id: "kimchy", session_data: { arbitrary_object: { some_array: [ "foo", "bar", { baz: 2, }, ], }, }, last_updated: "2015-12-06T18:20:22", }, }); console.log(response1); const response2 = await client.get({ index: "my-index-000001", id: "session_1", }); console.log(response2); const response3 = await client.indices.getMapping({ index: "my-index-000001", }); console.log(response3);
PUT my-index-000001 { "mappings": { "enabled": false } } PUT my-index-000001/_doc/session_1 { "user_id": "kimchy", "session_data": { "arbitrary_object": { "some_array": [ "foo", "bar", { "baz": 2 } ] } }, "last_updated": "2015-12-06T18:20:22" } GET my-index-000001/_doc/session_1 GET my-index-000001/_mapping
The entire mapping is disabled. |
|
The document can be retrieved. |
|
Checking the mapping reveals that no fields have been added. |
The enabled
setting for existing fields and the top-level mapping
definition cannot be updated.
Note that because Elasticsearch completely skips parsing the field contents, it is possible to add non-object data to a disabled field:
resp = client.indices.create( index="my-index-000001", mappings={ "properties": { "session_data": { "type": "object", "enabled": False } } }, ) print(resp) resp1 = client.index( index="my-index-000001", id="session_1", document={ "session_data": "foo bar" }, ) print(resp1)
response = client.indices.create( index: 'my-index-000001', body: { mappings: { properties: { session_data: { type: 'object', enabled: false } } } } ) puts response response = client.index( index: 'my-index-000001', id: 'session_1', body: { session_data: 'foo bar' } ) puts response
const response = await client.indices.create({ index: "my-index-000001", mappings: { properties: { session_data: { type: "object", enabled: false, }, }, }, }); console.log(response); const response1 = await client.index({ index: "my-index-000001", id: "session_1", document: { session_data: "foo bar", }, }); console.log(response1);