2

How to get all field names (not values) under _source using elastic4s ? I want a list of all mapped fields . I tried doing something like:

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

              )

or even

 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

              )

but that didn't do it . I got all metadata fields and not just those under _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 

==== Update ===

I found this way :

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

is there a better way for getting the same result ?

igx
  • 4,101
  • 11
  • 43
  • 88
  • Do you want a list of fields for each document or is it the same for the whole type? You can use `getMapping( / )` if it is per type – Pandawan Jan 10 '17 at 22:39
  • thanks, it looks like a good approach. checkout my update – igx Jan 11 '17 at 09:19

1 Answers1

1

use Get Mapping API

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

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

OR use Cluster API

GET /_cluster/state

FIELD LIST :

json -> metadata -> indices -> your_index -> mapping
harry
  • 483
  • 2
  • 12