1
如何使用elastic4s獲取_source下的所有字段名稱(不是值)?我想要一個所有映射字段的列表。 我試圖做這樣的事情:如何獲取elasticsearch中的所有字段
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
有沒有更好的方法得到相同的結果?
你想爲每個文檔的字段列表或者是它整個類型都一樣嗎?你可以使用'getMapping(/)',如果它是每個類型 –
Pandawan
謝謝,它看起來像一個好方法。結帳我的更新 – igx