小编lou*_*uis的帖子

在Elasticsearch中获取与特定查询相对应的映射

由于Elasticsearch的上一版本已在一个索引中弃用了多个类型,因此我通过类型为"keyword"的"doc_type"字段组织了我的数据,这使我能够运行如下查询:

curl 'localhost:9200/my_index/_search?pretty&q=doc_type:my_doc_type'
Run Code Online (Sandbox Code Playgroud)

此查询将返回doc_type字段为'my_doc_type'的所有文档.现在,我想仅检索来自此类请求的字段的映射.

为了重现这种情况,假设我们将索引映射定义如下:

curl -XPUT 'localhost:9200/my_index/my_type/_mapping?pretty' -H 'Content-Type: application/json' -d '{
  "my_type" : {
    "properties" : {
      "first_name" : {"type" : "text" },
      "last_name": {"type": "text"},
      "doc_type": {"type": "keyword"}
    }
  }
}'
Run Code Online (Sandbox Code Playgroud)

现在,让我们注入以下两个文件:

curl -XPUT 'localhost:9200/my_index/my_type/1' -H 'Content-Type: application/json' -d '{ "last_name": "Doe", "first_name": "John", "doc_type": "type_a"}'
curl -XPUT 'localhost:9200/my_index/my_type/1' -H 'Content-Type: application/json' -d '{ "first_name": "Jane", "doc_type": "type_b"}'
Run Code Online (Sandbox Code Playgroud)

我只能检索与查询匹配的文档的映射q=doc_type:type_b.在这种情况下,我应该只检索字段"keyword"和"first_name"的映射.

如果使用单个查询无法做到这一点,我知道Elasticsearch提供了一个特定的字段映射查询,但是要使用它,我首先需要检索与q=doc_type:type_b查询匹配的所有文档的所有字段联合.还有办法吗?

elasticsearch

6
推荐指数
1
解决办法
112
查看次数

标签 统计

elasticsearch ×1