在ElasticSearch中检索所有_id的有效方法
从ElasticSearch获取某个索引的所有_id的最快方法是什么?使用简单的查询是否可能?我的索引之一包含大约20,000个文档。
回答:
编辑:请也阅读@Aleck Landgraf的答案
您只想要elasticsearch-internal _id字段吗?还是id文档中的字段?
对于前者,请尝试
curl http://localhost:9200/index/type/_search?pretty=true -d '{ 
    "query" : { 
        "match_all" : {} 
    },
    "stored_fields": []
}
'
 该帖子最初包含在内,"fields": []但此后名称已更改,并且stored_fields是新值。
结果将仅包含文档的“元数据”
{  "took" : 7,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 4,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "index",
      "_type" : "type",
      "_id" : "36",
      "_score" : 1.0
    }, {
      "_index" : "index",
      "_type" : "type",
      "_id" : "38",
      "_score" : 1.0
    }, {
      "_index" : "index",
      "_type" : "type",
      "_id" : "39",
      "_score" : 1.0
    }, {
      "_index" : "index",
      "_type" : "type",
      "_id" : "34",
      "_score" : 1.0
    } ]
  }
}
对于后者,如果要包括文档中的字段,只需将其添加到fields数组中
curl http://localhost:9200/index/type/_search?pretty=true -d '{ 
    "query" : { 
        "match_all" : {} 
    },
    "fields": ["document_field_to_be_returned"]
}
'
以上是 在ElasticSearch中检索所有_id的有效方法 的全部内容, 来源链接: utcz.com/qa/435377.html






