如何获取elasticsearch中的所有字段

时间:2017-01-10 21:21:53

标签: elasticsearch elastic4s

如何使用elastic4s获取_source下的所有字段名称(而不是值)?我想要一个所有映射字段的列表。 我尝试过这样的事情:

search in indexName / indexType sourceInclude "_source" limit q.limit aggregations(
                aggregation terms "agg0" field "_field_names"  size 0

              )

甚至

 search in indexName / indexType sourceInclude "_source" sourceExclude ("_all", "_type",
                "_uid", "_version", "_index", "_score", "_id")  limit q.limit aggregations(
                aggregation terms "agg0" field "_field_names"  size 0

              )

但是没有这样做。我获得了所有元数据字段,而不仅仅是_source

下的字段
"aggregations" : {
    "agg0" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 0,
      "buckets" : [ {
        "key" : "_all",
        "doc_count" : 1500
      }, {
        "key" : "_source",
        "doc_count" : 1500
      }, {
        "key" : "_type",
        "doc_count" : 1500
      }, {
        "key" : "_uid",
        "doc_count" : 1500
      }, {
        "key" : "_version",
        "doc_count" : 1500
      }
.. more fields 

====更新===

我发现了这种方式:

val map = getMapping indexName /indexType}
val y = map.get("properties").asInstanceOf[java.util.Map[String, _]]
y.keys.toList

是否有更好的方法来获得相同的结果?

1 个答案:

答案 0 :(得分:1)

使用Get Mapping API

GET /index/_mapping
GET /index/_mapping/type

https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html

或使用Cluster API

GET /_cluster/state

现场清单:

json -> metadata -> indices -> your_index -> mapping