_ignored 字段

编辑

_ignored 字段索引并存储文档中在索引时被忽略的所有字段的名称。例如,当字段格式错误并且 ignore_malformed 设置为开启时,当 keyword 字段的值超过其可选的 ignore_above 设置时,或者当 index.mapping.total_fields.limit 已达到并且 index.mapping.total_fields.ignore_dynamic_beyond_limit 设置为 true 时,都可能发生这种情况。

此字段可使用 termtermsexists 查询进行搜索,并作为搜索命中的一部分返回。

例如,以下查询匹配所有具有一个或多个被忽略的字段的文档

resp = client.search(
    query={
        "exists": {
            "field": "_ignored"
        }
    },
)
print(resp)
response = client.search(
  body: {
    query: {
      exists: {
        field: '_ignored'
      }
    }
  }
)
puts response
const response = await client.search({
  query: {
    exists: {
      field: "_ignored",
    },
  },
});
console.log(response);
GET _search
{
  "query": {
    "exists": {
      "field": "_ignored"
    }
  }
}

类似地,以下查询查找索引时 @timestamp 字段被忽略的所有文档

resp = client.search(
    query={
        "term": {
            "_ignored": "@timestamp"
        }
    },
)
print(resp)
response = client.search(
  body: {
    query: {
      term: {
        _ignored: '@timestamp'
      }
    }
  }
)
puts response
const response = await client.search({
  query: {
    term: {
      _ignored: "@timestamp",
    },
  },
});
console.log(response);
GET _search
{
  "query": {
    "term": {
      "_ignored": "@timestamp"
    }
  }
}

自 8.15.0 版本起,_ignored 字段也支持聚合。例如,以下查询查找所有被忽略的字段

resp = client.search(
    aggs={
        "ignored_fields": {
            "terms": {
                "field": "_ignored"
            }
        }
    },
)
print(resp)
response = client.search(
  body: {
    aggregations: {
      ignored_fields: {
        terms: {
          field: '_ignored'
        }
      }
    }
  }
)
puts response
const response = await client.search({
  aggs: {
    ignored_fields: {
      terms: {
        field: "_ignored",
      },
    },
  },
});
console.log(response);
GET _search
{
  "aggs": {
    "ignored_fields": {
      "terms": {
         "field": "_ignored"
      }
    }
  }
}