首页 > 解决方案 > 如何在 ElasticSearch 上使用过滤器(或查询)条件获取所有字段名称?

问题描述

PUT /test-product
{
  "mappings": {
    "properties": {
      "profile": {
        "type": "nested"
      },
      "product": {
        "type": "nested"
      }
    }
  }
}

我有一个名为“测试产品”的索引

POST /test-product/_bulk
{ "index" : { "_id" : "1" } }
{ "user":"1", "profile":{"name":"AA", "age": "11", "height": "30"}, "product": {"price": "333", "name": "test", "weight": "10"} }
{ "index" : { "_id" : "2" } }
{ "user":"2", "profile":{"name":"BB", "age": "20"}, "product": {"name": "test"}}

并且该索引有一些文档

我想得到如下结果....

案例1.当我搜索用户时:1

profile.name、profile.age、profile.height、product.price、product.name、product.weight

案例2.当我搜索用户时:2

profile.name、profile.age、product.name

有办法吗?

标签: elasticsearchkibanaelastic-stackelasticsearch-5elasticsearch-7

解决方案


我不确定您对数据的要求是什么,但所有字段都可以使用GET <index>/_mapping. 也许GET index_name/_mapping?pretty会更适合你。


推荐阅读