栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在Elasticsearch中查找不同的内部对象

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在Elasticsearch中查找不同的内部对象

我们终于解决了我们的问题。

我们的解决方案是(如我们预期的那样)一个预先计算的

people_all
字段。但是在导入数据时,我们正在编写其他字段,而不是使用
copy_to
or
transform
而是在编写它。该字段如下所示:

"people": {  "type": "nested",  ..  "properties": {    "firstName": {      "type": "string",      "store": "yes",      "index": "not_analyzed"    },    "lastName": {      "type": "string",      "store": "yes",      "index": "not_analyzed"    },    "people_all": {      "type": "string",      "index": "not_analyzed"    }  }}

"index":"not_analyzed"
people_all
现场注意。这对于拥有完整的存储桶很重要。如果您不使用它,我们的示例将返回3个存储桶“ john”,“
jane”和“ doe”。

编写完这个新字段后,我们可以进行如下操作:

{  "size": 0,  "query": {    "term": {      "street": "Baker Street"    }  },  "aggs": {    "people_distinct": {      "nested": {        "path": "people"      },      "aggs": {        "people_all_distinct": {          "terms": { "field": "people.people_all", "size": 0          }        }      }    }  }}

我们返回以下响应:

{  "took": 2,  "timed_out": false,  "_shards": {    "total": 5,    "successful": 5,    "failed": 0  },  "hits": {    "total": 2,    "max_score": 0.0,    "hits": []  },  "aggregations": {    "people_distinct": {      "doc_count": 3,      "people_name_distinct": {        "doc_count_error_upper_bound": 0,        "sum_other_doc_count": 0,        "buckets": [          { "key": "John Doe", "doc_count": 2          },          { "key": "Jane Doe", "doc_count": 1          }        ]      }    }  }}

现在,在响应中,我们可以创建不同的人员对象。

请让我们知道是否有更好的方法来实现我们的目标。
解析存储桶不是最佳解决方案,

firstName
并且
lastName
在每个存储桶中都包含字段会更加有趣。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/406397.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号