简体   繁体   English

如何仅从 ElasticSearch 的源中获取内部字段?

[英]how can I fetch only inner fields from source in ElasticSearch?

I have index structure like this:我有这样的索引结构:

{
          "id" : 42,
          "Person" : {
            "contracts" : [
              {
                "contractID" : "000000000000102"
              }
            ],
            "Ids" : [
              3,
              387,
              100,
              500,
              274,
              283,
              328,
              400,
              600
            ]
          },
          "dateUpdate" : "2020-12-07T13:15:00.408Z"
        }
      },
      ...
}

I need a search query that will fetch only inner "Ids" field from source and nothing more.我需要一个搜索查询,它只会从源中获取内部“Ids”字段,仅此而已。 How can I do this?我怎样才能做到这一点?

You can use _source in inner_hits , in the following way您可以通过以下方式在inner_hits中使用_source

Index Mapping:索引映射:

{
  "mappings": {
    "properties": {
      "Person": {
        "type": "nested"
      }
    }
  }
}

Search Query:搜索查询:

{
  "query": {
    "bool": {
      "must": [
        {
          "nested": {
            "path": "Person",
            "query": {
              "match_all": {}
            },
            "inner_hits": {
              "_source": {
                "includes": [
                  "Person.Ids"
                ]
              }
            }
          }
        }
      ]
    }
  }
}

Search Result:搜索结果:

"inner_hits": {
          "Person": {
            "hits": {
              "total": {
                "value": 1,
                "relation": "eq"
              },
              "max_score": 1.0,
              "hits": [
                {
                  "_index": "65237264",
                  "_type": "_doc",
                  "_id": "1",
                  "_nested": {
                    "field": "Person",
                    "offset": 0
                  },
                  "_score": 1.0,
                  "_source": {
                    "Ids": [
                      3,
                      387,
                      100,
                      500,
                      274,
                      283,
                      328,
                      400,
                      600
                    ]
                  }
                }
              ]
            }
          }
        }

You can also use nested inner_hits and _souce , in the following way您还可以通过以下方式使用嵌套的inner_hits_souce

{
  "query": {
    "nested": {
      "path": "Person",
      "query": {
        "match_all": {}
      },
      "inner_hits": {
        "_source" : false,
        "docvalue_fields" : [
          {
            "field": "Person.Ids",
            "format": "use_field_mapping"
          }
        ]
      }
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Elasticsearch 字段仅用于 _source - Elasticsearch fields only for _source 如何从 Elasticsearch 返回源字段 - How to return source fields from Elasticsearch 如何从 elasticsearch 中的特定索引中获取数据? - How can i fetch data from a particular index in elasticsearch? 我如何从Elasticsearch获取不同的记录 - How can I fetch distinct records from Elasticsearch elasticsearch - 只返回没有_source的特定字段? - elasticsearch - only return specific fields without _source? 如何从 ElasticSearch 中的 _source 字段中排除某些字段 - How to exclude certain fields from the _source field in ElasticSearch 如何在Elasticsearch客户端搜索功能中仅获取'_source'字段? - How can I get only '_source' field in elasticsearch client search function? 过滤掉元数据字段,仅返回elasticsearch中的源字段 - Filter out metadata fields and only return source fields in elasticsearch 如何在具有JPA的Spring Boot中使用ElasticSearch,我是否必须从表中获取记录并将其放入Elasticsearch的索引中? - How to use ElasticSearch in spring boot having JPA in application, can I have to fetch records from table and put it in a index in elasticsearch? 如何从Elasticsearch数据源制作grafana中的累积和图? - How can I make a cumulative sum graph in grafana, from an elasticsearch data source?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM