gpt4 book ai didi

elasticsearch - 如何在Elasticsearch中获取所有字段

转载 作者:行者123 更新时间:2023-12-02 22:30:31 25 4
gpt4 key购买 nike

如何使用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

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

最佳答案

使用Get Mapping API

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

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

或使用集群API
GET /_cluster/state

栏位 list :
json -> metadata -> indices -> your_index -> mapping

关于elasticsearch - 如何在Elasticsearch中获取所有字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41578638/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com