是否可以在 Elasticsearch 中使用 doc_values=true 过滤非索引字段

Is it possible to filter on a non-indexed field with doc_values=true in Elasticsearch

在 Elasticsearch 5.6 中使用以下映射:

"category" => [
    "type"=>"keyword",
    "doc_values"=>true,
    "index"=>false
    "store"=>true
]

有人建议我可以编写一个查询来过滤这个字段,因为它的 doc_values 设置,即使索引属性设置为 false,但看起来 doc_values 字段仅对聚合和排序有用。

是否可以创建过滤该字段的查询?

Keyword datatypes have doc_values 默认启用。您不需要明确启用它。如果搜索精确文本,则可以在查询中过滤关键字字段。 例如,我有以下带有映射的索引

PUT index_name
{
  "mappings": {
    "type_name": {
      "properties": {
        "id": {
          "type": "long"
        },
        "name": {
          "type": "keyword"
        }
      }
    }
  }
}

示例文档:

{
    "id":1,
    "name":"hatim"
}

所以,我可以在查询部分像这样过滤搜索

GET index_name/type_name/_search
{
  "query": {
    "term": {
      "name": "hatim"
    }
  }
}

等等,你可以像这样在上面添加聚合

GET index_name/type_name/_search
{
  "query": {
    "term": {
      "name": "hatim"
    }
  },
  "aggs": {
    "count": {
      "value_count": {
        "field": "name"
      }
    }
  }
}

未编入索引的字段 by definition 不可搜索。 Elasticsearch 不会将其放入倒排索引(用于搜索)。如果您尝试 运行 搜索查询,您将收到类似 Cannot search on field [category] since it is not indexed.

的错误