enabled
Elasticsearch пытается индексировать все поля, которые вы ему предоставляете, но иногда вы хотите просто сохранить поле без индексирования. Например, представьте, что вы используете Elasticsearch в качестве хранилища веб-сессий. Вы можете захотеть индексировать идентификатор сессии и время последнего обновления, но вам не нужно выполнять запросы или агрегации по самим данным сессии.
Настройка enabled, которую можно применить только к определению отображения верхнего уровня и к полям типа object, заставляет Elasticsearch пропустить полное разбор содержимого поля. JSON всё ещё можно получить из поля _source, но оно не является поисковым и не хранится каким-либо другим способом:
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"
} | Поле | |
| Любые произвольные данные могут быть переданы в поле | |
|
|
Также можно отключить всю схему, в этом случае документ хранится в поле _source, что означает, что его можно получить, но его содержимое не индексируется никаким образом:
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 | Вся схема отключена. | |
| Документ может быть получен. | |
| Проверка схемы показывает, что поля не были добавлены. |
Настройка enabled для существующих полей и определения схемы верхнего уровня не может быть обновлена.
Обратите внимание, что поскольку Elasticsearch полностью пропускает разбор содержимого поля, можно добавить данные, которые не являются объектами, в отключенное поле:
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); PUT my-index-000001
{
"mappings": {
"properties": {
"session_data": {
"type": "object",
"enabled": false
}
}
}
}
PUT my-index-000001/_doc/session_1
{
"session_data": "foo bar"
} | Документ добавлен успешно, даже если |
© 2023-2025 Elasticsearch
As of September 2024, Elasticsearch is available under a choice of three licenses: the Server Side Public License (SSPL), the Elastic License, or the AGPLv3 (OSI approved).
Elasticsearch and the Elasticsearch logo are trademarks of Elasticsearch B.V., registered in the U.S. and in other countries.
https://www.elastic.co/guide/en/elasticsearch/reference/8.17/enabled.html