如何使用 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
有没有更好的方法来获得相同的结果?