dataframe - 在 Elastic Search 中使用某些字段和某些条件进行查询?
问题描述
我有关于产品的数据,其中有一些字段(_id, Shop, ProductVerion
...)。它已在 Elastic Search 中编入索引。我想用 Shop 搜索具有最大 ProductVersion 的产品。
前任:
Shop Amazon has 3 Version crawl product: 111,222,333.
Shop Ebay has 2 version: 222,444
Shop Alibaba has 2 version: 111, 444
版本可能相同。
现在,我想获得具有以下功能的产品:
Shop Amazon and ProducVersion 333
or Shop Ebay and ProductVersion 444
or Shop Alibaba and ProductVersion 444.
但我不知道查询。帮帮我,请!
解决方案
我用一些示例文档进行了尝试。我将版本字段保留为数字字段。
这些是我尝试过的示例文档
[
{
"_index": "test",
"_type": "doc",
"_id": "12334",
"_score": 1,
"_source": {
"shopName": "amazon",
"version": 341
}
},
{
"_index": "test",
"_type": "doc",
"_id": "123",
"_score": 1,
"_source": {
"shopName": "amazon",
"version": 3412
}
},
{
"_index": "test",
"_type": "doc",
"_id": "1233",
"_score": 1,
"_source": {
"shopName": "amazon",
"version": 341
}
},
{
"_index": "test",
"_type": "doc",
"_id": "1238",
"_score": 1,
"_source": {
"shopName": "alibaba",
"version": 34120
}
},
{
"_index": "test",
"_type": "doc",
"_id": "1239",
"_score": 1,
"_source": {
"shopName": "alibaba",
"version": 3414
}
},
{
"_index": "test",
"_type": "doc",
"_id": "123910",
"_score": 1,
"_source": {
"shopName": "alibaba",
"version": 124
}
}
]
正如@demas 指定的那样,我继续进行术语聚合和热门聚合
indexName/_search
{
"size": 0,
"aggs": {
"shop": {
"terms": {
"field": "shopName.keyword"
},
"aggs": {
"product": {
"top_hits": {
"size": 1,
"sort": [
{
"version": {
"order": "desc"
}
}
]
}
}
}
}
}
}
这应该为您提供包含每个商店的最高产品版本号的文档,如下所示。
{
"took": 8,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 6,
"max_score": 0,
"hits": []
},
"aggregations": {
"shop": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "alibaba",
"doc_count": 3,
"product": {
"hits": {
"total": 3,
"max_score": null,
"hits": [
{
"_index": "test",
"_type": "doc",
"_id": "1238",
"_score": null,
"_source": {
"shopName": "alibaba",
"version": 34120
},
"sort": [
34120
]
}
]
}
}
},
{
"key": "amazon",
"doc_count": 3,
"product": {
"hits": {
"total": 3,
"max_score": null,
"hits": [
{
"_index": "test",
"_type": "doc",
"_id": "123",
"_score": null,
"_source": {
"shopName": "amazon",
"version": 3412
},
"sort": [
3412
]
}
]
}
}
}
]
}
}
}
推荐阅读
- docusignapi - 可以使用 Docusign API 实现以下功能吗?
- android - FCM 服务器密钥的知识能给攻击者带来什么?
- laravel - Error adding new event to google calender Google_Service_Exception (401) { "error": "unauthorized_client", "error_description": "Unauthorized" }
- java - 使用 apache activiti 检查下一个任务是否是结束事件
- kubernetes - Kubernetes github 存储库中有关 Cgroup 数据的代码在哪里?
- flutter - 如何在 Flutter 中对连接包进行单元测试
- python - 检测时间序列中的状态变化
- python - matplotlib - What am I doing wrong here?
- excel - 具有两个条件的 Instr 函数
- java - 如何限制 Firebase 电子邮件登录中的错误密码尝试?