ignore_malformed
Иногда у вас мало контроля над данными, которые вы получаете. Один пользователь может отправить поле login, которое является типом date, а другой — поле login, которое является адресом электронной почты.
Попытка индексировать неправильный тип данных в поле по умолчанию вызывает исключение и отбрасывает весь документ. Параметр ignore_malformed, если установлен в значение true, позволяет игнорировать исключение. Неправильно сформированное поле не индексируется, но другие поля в документе обрабатываются нормально.
Например:
resp = client.indices.create(
index="my-index-000001",
mappings={
"properties": {
"number_one": {
"type": "integer",
"ignore_malformed": True
},
"number_two": {
"type": "integer"
}
}
},
)
print(resp)
resp1 = client.index(
index="my-index-000001",
id="1",
document={
"text": "Some text value",
"number_one": "foo"
},
)
print(resp1)
resp2 = client.index(
index="my-index-000001",
id="2",
document={
"text": "Some text value",
"number_two": "foo"
},
)
print(resp2) response = client.indices.create(
index: 'my-index-000001',
body: {
mappings: {
properties: {
number_one: {
type: 'integer',
ignore_malformed: true
},
number_two: {
type: 'integer'
}
}
}
}
)
puts response
response = client.index(
index: 'my-index-000001',
id: 1,
body: {
text: 'Some text value',
number_one: 'foo'
}
)
puts response
response = client.index(
index: 'my-index-000001',
id: 2,
body: {
text: 'Some text value',
number_two: 'foo'
}
)
puts response const response = await client.indices.create({
index: "my-index-000001",
mappings: {
properties: {
number_one: {
type: "integer",
ignore_malformed: true,
},
number_two: {
type: "integer",
},
},
},
});
console.log(response);
const response1 = await client.index({
index: "my-index-000001",
id: 1,
document: {
text: "Some text value",
number_one: "foo",
},
});
console.log(response1);
const response2 = await client.index({
index: "my-index-000001",
id: 2,
document: {
text: "Some text value",
number_two: "foo",
},
});
console.log(response2); PUT my-index-000001
{
"mappings": {
"properties": {
"number_one": {
"type": "integer",
"ignore_malformed": true
},
"number_two": {
"type": "integer"
}
}
}
}
PUT my-index-000001/_doc/1
{
"text": "Some text value",
"number_one": "foo"
}
PUT my-index-000001/_doc/2
{
"text": "Some text value",
"number_two": "foo"
} | В этом документе поле | |
| Этот документ будет отклонен, потому что |
Настройка ignore_malformed в настоящее время поддерживается следующими типами картирования:
Значение настройки ignore_malformed можно обновить для существующих полей с помощью API обновления схемы.
Значение по умолчанию на уровне индекса
Настройка index.mapping.ignore_malformed может быть установлена на уровне индекса для глобального игнорирования неправильно сформированного содержимого во всех разрешенных типах картирования. Типы картирования, которые не поддерживают эту настройку, проигнорируют её, если она установлена на уровне индекса.
resp = client.indices.create(
index="my-index-000001",
settings={
"index.mapping.ignore_malformed": True
},
mappings={
"properties": {
"number_one": {
"type": "byte"
},
"number_two": {
"type": "integer",
"ignore_malformed": False
}
}
},
)
print(resp) response = client.indices.create(
index: 'my-index-000001',
body: {
settings: {
'index.mapping.ignore_malformed' => true
},
mappings: {
properties: {
number_one: {
type: 'byte'
},
number_two: {
type: 'integer',
ignore_malformed: false
}
}
}
}
)
puts response const response = await client.indices.create({
index: "my-index-000001",
settings: {
"index.mapping.ignore_malformed": true,
},
mappings: {
properties: {
number_one: {
type: "byte",
},
number_two: {
type: "integer",
ignore_malformed: false,
},
},
},
});
console.log(response); PUT my-index-000001
{
"settings": {
"index.mapping.ignore_malformed": true
},
"mappings": {
"properties": {
"number_one": {
"type": "byte"
},
"number_two": {
"type": "integer",
"ignore_malformed": false
}
}
}
} | Поле | |
| Поле |
Обработка неправильно сформированных полей
Неправильно сформированные поля молча игнорируются во время индексирования, когда ignore_malformed включено. По возможности рекомендуется ограничивать количество документов с неправильно сформированным полем, иначе запросы к этому полю станут бессмысленными. Elasticsearch упрощает проверку количества документов с неправильно сформированными полями с помощью запросов exists, term или terms на специальное поле _ignored.
Пределы для JSON-объектов
Вы не можете использовать ignore_malformed со следующими типами данных:
Вы также не можете использовать ignore_malformed для игнорирования JSON-объектов, отправленных в поля неправильного типа данных. JSON-объект — это любые данные, заключенные в фигурные скобки "{}" и содержащие данные, сопоставленные со вложенными, объектами и диапазонными типами данных.
Если вы отправляете JSON-объект в неподдерживаемое поле, Elasticsearch вернет ошибку и отклонит весь документ независимо от настройки ignore_malformed.
© 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/ignore-malformed.html