已忽略
_ignored
字段帮助您管理文档中格式错误数据相关的问题。由于在索引映射中启用了 ignore_malformed
设置,此字段用于索引和存储在索引过程中被忽略的字段名。
_ignored
字段允许您搜索并识别包含被忽略字段的文档,以及识别被忽略的具体字段名。这对于故障排除很有用。
您可以使用 term
、terms
和 exists
查询来查询 _ignored
字段,查询结果将包含在搜索命中中。
_ignored
字段仅当您的索引映射中启用了 ignore_malformed
设置时才会被填充。如果 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": []
}
}