gpt4 book ai didi

elasticsearch - 如何获取elasticsearch索引中的所有字段名

转载 作者:行者123 更新时间:2023-11-29 02:56:04 28 4
gpt4 key购买 nike

我刚开始使用 elasticsearch 5.2。

我正在尝试获取索引中的所有键 如果我有以下映射:

"properties": {
"name": { "type": "text" },
"article": {
"properties": {
"id": { "type": "text" },
"title": { "type": "text"},
"abstract": { "type": "text"},
"author": {
"properties": {
"id": { "type": "text" },
"name": { "type": "text" }
}}}} } }

是否可以获取所有字段的全名? 像这样:

 name,
article.id ,
article.title ,
article.abstract ,
article.author.id,
article.author.name

我怎样才能得到它?

最佳答案

您可以使用 _field_names字段。

The _field_names field indexes the names of every field in a document that contains any value other than null.

GET _search
{
"size"0,
"aggs": {
"Field names": {
"terms": {
"field": "_field_names",
"size": 100
}
}
}
}

更新:从 ES 5 开始

the _field_names field has been locked down and is only indexed, it doesn't support fielddata (memory intensive) or doc values,

引用:https://github.com/elastic/elasticsearch/issues/22576

作为替代方案,您可以 getMapping API

The get mapping API can be used to get more than one index or type mapping with a single call. General usage of the API follows the following syntax: host:port/{index}/_mapping/{type}

$ curl -XGET 'http://localhost:9200/index/_mapping?pretty'

然后您可以处理响应以提取索引中的所有字段名称

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

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