elasticsearch中的嵌套聚合
我正在尝试使用elasticsearch实现自动完成功能。我正在研究的索引结构如下所示elasticsearch中的嵌套聚合,
Warning: implode(): Invalid arguments passed in /data/phpspider/zhask/webroot/tpl/detail.html on line 45
,,我正在尝试使用elasticsearch实现自动完成功能。我正在研究的索引结构如下所示 "title": "blog post 1", "body": "body of the blog post", "category": "programming", "locations": [ {"name": "united states"}, {"name": "new york"}, {"name": "venice"} ] 我正在尝试使用嵌套聚合。我正在使用的映射是
"title": "blog post 1",
"body": "body of the blog post",
"category": "programming",
"locations": [
{"name": "united states"},
{"name": "new york"},
{"name": "venice"}
]
我正在尝试使用嵌套聚合。我正在使用的映射是
{
blog : {
mappings : {
tag : {
properties : {
body : {
type : string
},
category : {
type : string
},
locations : {
properties : {
name : {
type : string
}
}
},
title : {
type : string
}
}
}
}
}
}
根据位置聚合结果的查询。name
为
GET /blog/tag/_search
{
"size": 0,
"query": {
"match": {
"locations.name": "montreal"
}
},
"aggs": {
"aggregated_locations": {
"nested": {
"path": "locations"
},
"aggs": {
"filtered_locations": {
"terms": {
"fields": "locations.name"
}
}
}
}
}
}
目前,我正在使用用于elasticsearch的chrome插件执行上述请求。上面的查询给出了一个错误,很长,但是如果有人提示,我也可以发布它。我想我在解释嵌套聚合的含义时可能是错误的,这意味着我的映射是错误的。但我无法找出问题所在。映射中缺少一些部分,您需要将“位置”字段设置为“嵌套”类型,而不分析内部字段,以便能够根据您的期望进行聚合:
PUT blog
{
"mappings": {
"tag": {
"properties": {
"body": {
"type": "string"
},
"category": {
"type": "string"
},
"locations": {
"type": "nested",
"properties": {
"name": {
"type": "string",
"index": "not_analyzed"
}
}
},
"title": {
"type": "string"
}
}
}
}
}
然后运行以下查询以对嵌套字段进行筛选,并对嵌套字段进行聚合:
GET blog/_search
{
"size": 0,
"query": {
"nested": {
"path": "locations",
"query": {
"match": {
"locations.name": "montreal"
}
}
}
},
"aggs": {
"aggregated_locations": {
"nested": {
"path": "locations"
},
"aggs": {
"filtered": {
"terms": {
"field": "locations.name"
}
}
}
}
}
}
可以复制/粘贴这些查询()我使用-->
curl-XGET'localhost:9200/blog/_-mapping/tag?pretty'>!test.json
以获取新映射。但是test.json是一个巨大的文件。它有许多冗余。这是正常的行为吗?那么,我所做的就是删除我的索引,运行映射,然后创建新的索引……我的工作流有什么问题吗?我是elasticsearch新手。您无法更新映射,工作流是正确的,您需要先删除索引。这里有一篇博客文章解释了这一点(),并提供了零停机时间的指南。完全相同的映射和查询在我的chrome sense扩展中不起作用。使用上述指定的查询和映射是否需要elasticsearch 2.0,我当前使用elasticsearch 1.7如果查询找到查询中定义的特定位置,则返回位置列表中的所有元素。我只希望bucket只有一个被查询的位置