- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图在一个字段上聚合,并使用top_ hits
获取最高记录,但我想在响应中包括嵌套属性映射中未包括的其他字段。当前,如果我指定_source:{"include":[]}
,那么我只能获得当前嵌套属性中的字段。
这是我的 map
{
"my_cart":{
"mappings":{
"properties":{
"store":{
"properties":{
"name":{
"type":"keyword"
}
}
},
"sales":{
"type":"nested",
"properties":{
"Price":{
"type":"float"
},
"Time":{
"type":"date"
},
"product":{
"properties":{
"name":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword"
}
}
}
}
}
}
}
}
}
}
}
更新
"aggregations" : {
"aggregate_by_most_sold_product" : {
"doc_count" : 2878592,
"all_products" : {
"buckets" : [
{
"key" : "shampoo",
"doc_count" : 1,
"lastSold" : {
"value" : 1.602569793E12,
"value_as_string" : "2018-10-13T06:16:33.000Z"
},
"using_reverse_nested" : {
"doc_count" : 1,
"latest product" : {
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 0.0,
"hits" : [
{
"_index" : "my_cart",
"_type" : "_doc",
"_id" : "36303258-9r7w-4b3e-ba3d-fhds7cfec7aa",
"_source" : {
"cashier" : {
"firstname" : "romeo",
"uuid" : "2828dhd-0911-7229-a4f8-8ab80dde86a6"
},
"product_price": {
"price":20,
"discount_offered":10
},
"sales" : [
{
"product" : {
"name" : "shampoo",
"time":"2018-10-13T04:44:26+00:00
},
"product" : {
"name" : "noodles",
"time":"2018-10-13T04:42:26+00:00
},
"product" : {
"name" : "biscuits",
"time":"2018-10-13T04:41:26+00:00
}
}
]
}
}
]
}
}
]
预期响应
最佳答案
除非您使用 nested
,否则reverse_nested
上下文无法访问父级。但是,在这种情况下,您将失去仅检索适用的嵌套子文档的功能。但是幸运的是,有一种方法可以生成sort a terms
aggregation by the result of a different, numeric one:
GET my_cart/_search
{
"size": 0,
"aggs": {
"aggregate": {
"nested": {
"path": "sales"
},
"aggs": {
"all_products": {
"terms": {
"field": "sales.product.name.keyword",
"size": 6500,
"order": { <--
"lowest_date": "asc"
}
},
"aggs": {
"lowest_date": { <--
"min": {
"field": "sales.Time"
}
},
"using_reverse_nested": {
"reverse_nested": {}, <--
"aggs": {
"latest product": {
"top_hits": {
"_source": {
"includes": [
"store.name"
]
},
"size": 1
}
}
}
}
}
}
}
}
}
}
需要注意的是,您不会将
store.name
放入
top_hits
内-尽管我怀疑您可能已经在客户端进行了一些后期处理,可以合并这些条目:
"aggregate" : {
...
"all_products" : {
...
"buckets" : [
{
"key" : "myproduct", <--
...
"using_reverse_nested" : {
...
"latest product" : {
"hits" : {
...
"hits" : [
{
...
"_source" : {
"store" : {
"name" : "mystore" <--
}
}
}
]
}
}
},
"lowest_date" : {
"value" : 1.4200704E12,
"value_as_string" : "2015/01/01" <--
}
}
]
}
}
关于elasticsearch - 将父_source字段包括在嵌套的热门匹配中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64314470/
禁用 _source 的确切后果是什么? Elasticsearch 映射中的字段? 令人惊讶的简短documentation在 _source字段本身只是声明 Though very handy t
我正在向 http://localhost:9200/movie_db/movie/_search 发布查询,但 _source 属性在返回结果中始终为空。我启用了它,但这没有用。 电影数据库: TR
使用 Elasticsearch 1.4.3 我正在构建一种“报告”系统。客户可以挑选他们想要在结果中返回的字段。 在 90% 的情况下,客户端永远不会选择所有字段,所以我想我可以在映射中禁用 _so
我在 Elasticsearch 中有以下格式的记录: { "_index" : "feb14", "_type" : "apache_access", "_id
我正在尝试为Elasticsearch 6.7创建映射,但是当我获得记录时,除非启用_source,否则我看不到任何映射的字段。 我有以下示例: PUT xyz { "mappings":{
我在elastic-search 5中有一个文档,如下 { "_index": "my_index", "_type": "json", "_id": "document_id", "
"_source": { "id": "5b1676493d21784208c36041", "label": "name", "properti
我正在探索 ElasticSearch,用于应用程序,它将处理大量数据并生成一些统计结果。我的要求是检索特定字段的某些统计信息。例如,对于给定的字段,我想检索其唯一值和每个值的文档频率,以及值的长度。
当我使用(官方)nodejs-elasticsearch 库执行搜索查询时,是否可以仅检索 _source 文档?根据文档,似乎有一种方法: Use the /{index}/{type}/{id}/
我是elasticsearch的新手,我正在做一个匹配所有查询,它以这种方式检索数据,但只有我想要在_source中检索数据,我该怎么做?有什么想法吗? { "took": 4, "t
当输入JSON具有“_source”字段时,则输出JSON没有针对搜索的输出。 有两种情况。 情况_1:输入JSON确实具有“_source”字段,并且输出为Null 情况_2:输入JSON没有“_s
我需要实现一个搜索引擎。像谷歌/雅虎搜索一样,在搜索组件中,如果输入任何键,它应该找到匹配项并显示。为此,我创建了与 Elasticsearch 集成的 Spring Boot 项目。 我使用 log
我有一个正在尝试解决的性能问题...我正在从 AWS 托管 Elasticsearch 6.2 中的源索引到目标索引进行即时重新索引。源索引目前大小为数百 GB,并且在生产中可能会更大。因此,重新索引
我尝试对包含自定义脚本函数的 ElasticSearch (6.4.0) API 执行搜索请求。在这个函数中,我尝试访问一个数组,它应该是响应数据的一部分。但我总是得到一个“null_pointer_
我在索引文档的 _source 中有很多字段。但是,我不需要将所有这些都从搜索查询中返回。现在,对于每个找到的文档,都会返回整个 _source。我如何才能强制只接收每个 _source 的特定字段?
我有以下映射 { "cloth": { "dynamic" : false, "_source" : {"enabled"
我仅通过几个字段进行搜索,但我希望能够将整个文档存储在 ES 中,以免进行额外的 DB (MySQL) 查询。 我尝试将 index: no、store: no 添加到映射中的整个对象/属性,但我仍然
问题 如题:elasticsearch 从 _source 与 stored_fields 获取数据不一致? 大伙都知道,使用 elasticsearch 进行数据存储的时候,查询数据会默认存储在_s
在某些情况下会很好(我有固定数量的字段可显示在搜索结果上,并创建逻辑来替换“突出显示”集合中的一个字段,而第二个字段则保留原始字段在某种程度上令人不舒服)。可能吗? "hits": [ {
只是想知道。 是否可以在 _source = false 的索引上突出显示 ElasticSearch 中的文本? 我的意思是我知道如果 ES 没有他不能做高亮的文档,但是有没有办法只使用 ES 作为
我是一名优秀的程序员,十分优秀!