Ignored 忽略属性 #
_ignored
字段帮助您管理文档中与格式错误数据相关的问题。由于在
索引映射中启用了 ignore_malformed 设置,此字段用于存储在数据索引过程中被忽略的字段名称。
_ignored
字段允许您搜索和识别包含被忽略字段的文档,以及被忽略的具体字段名称。这对于故障排除很有用。
您可以使用 term
、terms
和 exists
查询来查询 _ignored
字段。
只有当索引映射中启用了
ignore_malformed
设置时,才会填充_ignored
字段。如果ignore_malformed
设置为false
(默认值),则格式错误的字段将导致整个文档被拒绝,并且不会填写_ignored
字段。
以下示例展示了如何使用 _ignored
字段:
GET _search
{
"query": {
"exists": {
"field": "_ignored"
}
}
}
使用 _ignored
字段的索引请求示例
#
以下示例向 test-ignored
索引添加一个新文档,其中 ignore_malformed
设置为 true
,这样在数据索引时不会抛出错误:
PUT test-ignored
{
"mappings": {
"properties": {
"title": {
"type": "text"
},
"length": {
"type": "long",
"ignore_malformed": true
}
}
}
}
POST test-ignored/_doc
{
"title": "correct text",
"length": "not a number"
}
GET test-ignored/_search
{
"query": {
"exists": {
"field": "_ignored"
}
}
}
示例返回内容 #
{
"took": 42,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 1,
"hits": [
{
"_index": "test-ignored",
"_id": "qcf0wZABpEYH7Rw9OT7F",
"_score": 1,
"_ignored": [
"length"
],
"_source": {
"title": "correct text",
"length": "not a number"
}
}
]
}
}
忽略指定字段 #
您可以使用 term
查询来查找特定字段被忽略的文档,如以下示例请求所示:
GET _search
{
"query": {
"term": {
"_ignored": "created_at"
}
}
}
返回内容 #
{
"took": 51,
"timed_out": false,
"_shards": {
"total": 45,
"successful": 45,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 0,
"relation": "eq"
},
"max_score": null,
"hits": []
}
}