这是我的示例文档,我在kibana的帮助下为类似文档编制索引。
{
"id": 15,
"name": "abcd",
"source": "csv_status",
"profile_complition": "70%",
"creation_date": "2020-04-02",
"current_position": [
{
"position": "Financial Reporting",
"position_category": "Finance",
"position_level": 2
}
],
"seeking_position": [
{
"position": "Financial Planning and Analysis",
"position_category": "Finance",
"position_level": 3
}
],
"last_updation_date": "2021-02-02",
"experience": [
{
"brand": "Other",
"company": "Other-Apartments and Residences",
"brand_segment": "Luxury",
"property_type": "All-Inclusive",
"duration": "2 years",
"real_estate_type": "Institutional"
},
{
"brand": "Accor",
"company": "Accor LLC",
"brand_segment": "Luxury",
"property_type": "Condo",
"duration": "2 years",
"real_estate_type": "Family Office"
},
{
"brand": "SO",
"company": "Accor LLC",
"brand_segment": "Luxury",
"property_type": "Condo",
"duration": "2 years",
"real_estate_type": "Family Office"
},
{
"brand": "Other",
"company": "Other-Multi-Family",
"brand_segment": "Independent",
"property_type": "Convention",
"duration": "2 years",
"real_estate_type": "Family Office"
},
{
"brand": "Other Lifestyle – Luxury",
"company": "Other Lifestyle – Luxury",
"brand_segment": "Extended Stay",
"property_type": "Condo",
"duration": "2 years",
"real_estate_type": "Family Office"
}
]
}
现在在文件中,“体验”下的关键“品牌”是主集团“公司”的子集团。正如您在文档中看到的,“品牌”可能有类似于“其他”的条目,但由“公司”键分隔。类似的结构可以在文档内部和文档之间出现。我打算根据“品牌”和“公司”来汇总文档。我尝试的查询是-
GET user_data1/_search
{
"size": 0,
"aggs": {
"nested_aggs": {
"nested": {
"path": "experience"
},
"aggs": {
"by_brand": {
"terms": {
"field": "experience.brand"
},
"aggs": {
"by_company": {
"terms": {
"field": "experience.company"
}
}
}
}
}
}
}
}
我得到的错误为-
{
"error" : {
"root_cause" : [
{
"type" : "aggregation_execution_exception",
"reason" : "[nested] nested path [experience] is not nested"
}
],
"type" : "search_phase_execution_exception",
"reason" : "all shards failed",
"phase" : "query",
"grouped" : true,
"failed_shards" : [
{
"shard" : 0,
"index" : "user_data1",
"node" : "aa0oyCw6RLa2J5aDALunsA",
"reason" : {
"type" : "aggregation_execution_exception",
"reason" : "[nested] nested path [experience] is not nested"
}
}
]
},
"status" : 500
}
这是我的文档的映射-
{
"user_data1" : {
"aliases" : { },
"mappings" : {
"properties" : {
"creation_date" : {
"type" : "date"
},
"current_position" : {
"properties" : {
"position" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"position_category" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"position_level" : {
"type" : "long"
}
}
},
"experience" : {
"properties" : {
"brand" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"brand_segment" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"company" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"duration" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"property_type" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"real_estate_type" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"id" : {
"type" : "long"
},
"last_updation_date" : {
"type" : "date"
},
"name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"profile_complition" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"seeking_position" : {
"properties" : {
"position" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"position_category" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"position_level" : {
"type" : "long"
}
}
},
"source" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"settings" : {
"index" : {
"routing" : {
"allocation" : {
"include" : {
"_tier_preference" : "data_content"
}
}
},
"number_of_shards" : "1",
"provided_name" : "user_data1",
"creation_date" : "1615227708037",
"number_of_replicas" : "1",
"uuid" : "8B3dnDKKQjmDNkjAksduJQ",
"version" : {
"created" : "7100299"
}
}
}
}
}
我知道我的经验字段没有嵌套,可能是这个错误的原因。我对elasticsearch相对较新,因此在索引时很难使我的文档嵌套类型。我尝试通过映射并填充文档来使其嵌套,但错误仍然存在。帮我
如果需要进一步澄清,请告知我
该错误清楚地表明体验字段不是嵌套类型。您需要将索引映射修改为-
{
"mappings": {
"properties": {
"experience": {
"type": "nested"
}
}
}
}
点击问题中给出的相同搜索查询,搜索结果为
"aggregations": {
"nested_aggs": {
"doc_count": 5,
"by_brand": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "Other",
"doc_count": 2,
"by_company": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "Other-Apartments and Residences",
"doc_count": 1
},
{
"key": "Other-Multi-Family",
"doc_count": 1
}
]
}
},
{
"key": "Accor",
"doc_count": 1,
"by_company": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "Accor LLC",
"doc_count": 1
}
]
}
},
{
"key": "Other Lifestyle – Luxury",
"doc_count": 1,
"by_company": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "Other Lifestyle – Luxury",
"doc_count": 1
}
]
}
},
{
"key": "SO",
"doc_count": 1,
"by_company": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "Accor LLC",
"doc_count": 1
}
]
}
}
]
}
}
}
我如何对键上的elasticsearch聚合桶进行排序。我有嵌套的聚合,想对我的第二个聚合桶结果进行排序。 就像我有: 我希望我的< code >事件聚集桶在关键< code >印象或< code >页面视图上按desc/asc排序。我如何实现这样的结果集? 这是我的查询 我试过使用_key,但它在桶内排序。我想通过查看所有桶来排序。就像我有一个键。我希望我的桶结果用这个键排序。不在桶内。 我希望
我已经为一个问题挣扎了一段时间,所以我想我应该通过stackoverflow来解决这个问题。 “我的文档类型”有一个标题、一个语言字段(用于筛选)和一个分组id字段(我省略了所有其他字段以保持重点) 搜索文档时,我希望找到包含标题中文本的所有文档。对于每个唯一的分组id,我只需要一个文档。 我一直在关注tophits聚合,从我所看到的情况来看,它应该能够解决我的问题。 对我的索引运行此查询时: 我
我正在尝试对弹性搜索聚合的结果桶进行排序。我有一大套文件: 我目前正在做的是使用top_hits聚合获取每个的最新销售: 现在,我想按任意字段对生成的bucket进行排序。如果我想按排序,我可以使用这个问题的解决方案,添加一个aggregation,它从每个bucket中提取 字段,最后添加一个 的字母顺序排序,我不能使用< code>max聚合,因为它只对数值字段有效。 如何按文本字段对存储桶(
我知道elasticsearch允许子聚合(即嵌套聚合),但是我想对“第一次”聚合的结果应用聚合(或者在通用的任何查询中-聚合与否)。 具体示例:我记录有关用户操作的事件(为简单起见,我有带有和的文档)。我可以进行查询,计算每个用户执行的操作数量。但是我想找出“活跃用户”的百分比(或计数)(例如,执行了10个以上操作的用户)。理想的结果是所有用户的直方图,显示用户的活跃程度。 有没有办法创建这样的
我试图使用过滤器聚合来支持前端的多选择方面值。 我有颜色和深度滤镜。 滤色器保存值:黑色(5)、蓝色(3)、红色(2) 深度过滤器保持值:70mm(3)、60mm(5)、50mm(3) 当我在滤色器中选择黑色时,所有其他选项(蓝色,红色)都没有响应。 我尝试添加 谢了,Sree。
我需要在其中一个索引中进行聚合排序分页。 我了解了弹性搜索的内部功能, 我总共有5个分片,它会对各个分片进行排序并获取结果,默认情况下每个分片将返回10条记录。然后再次对50条记录进行排序,它将获取前10条记录,因为默认大小为10。 输出: 聚合结果在名为“聚合”的单独字段中返回。为了在此聚合数据中进行分页,size和from不起作用。 厌倦了做termBuilder.size(500),现在逻辑