ignore_malformed
编辑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
设置当前受以下 映射类型支持:
可以使用 更新映射 API 更新现有字段上的 ignore_malformed
设置值。
索引级默认值
编辑可以在索引级别设置 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);