我刚开始使用 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" }
}}}} } }
Run Code Online (Sandbox Code Playgroud)
是否可以获取所有字段的全名? 像这样:
name,
article.id ,
article.title ,
article.abstract ,
article.author.id,
article.author.name
Run Code Online (Sandbox Code Playgroud)
我怎么能得到呢?
您可以使用_field_names字段。
_field_names 字段对文档中包含除 null 之外的任何值的每个字段的名称进行索引。
GET _search
{
"size"0,
"aggs": {
"Field names": {
"terms": {
"field": "_field_names",
"size": 100
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
更新:从 ES 5 开始
_field_names 字段已被锁定并且仅被索引,它不支持 fielddata (内存密集型)或 doc 值,
参考: https: //github.com/elastic/elasticsearch/issues/22576
作为替代方案,您可以获取Mapping API
获取映射 API 可用于通过一次调用获取多个索引或类型映射。API 的一般用法遵循以下语法:host:port/{index}/_mapping/{type}
$ curl -XGET 'http://localhost:9200/index/_mapping?pretty'
Run Code Online (Sandbox Code Playgroud)
然后,您可以处理响应以提取索引中的所有字段名称
| 归档时间: |
|
| 查看次数: |
12141 次 |
| 最近记录: |