【发布时间】:2015-05-26 14:04:05
【问题描述】:
在弹性搜索中,我得到了几十万个大致这种结构的文档:
{
"script": "/index.html",
"query": {
"ab": "hello",
"cd": "world",
"ef": "123"
}
url "http://localhost/index.html?ab=hello&cd=world&ef=123" 被解析到其中。 “脚本”只包含路径和目标脚本 - 根本没有查询。 查询数组不包含相同的键列表,当然还有不同的值,这在此刻根本不重要。
我知道,我可以通过以下方式获得不同的“脚本”列表:
{
"aggregations": {
"my_agg": {
"terms": {
"field": "script.raw"
}
}
}
}
这会导致多个桶,例如
"buckets": [
{
"key": "/index.html",
"doc_count": 123456
},
{
"key": "/hello.html",
"doc_count": 1456
},
...
我的问题:有没有办法额外获取所有查询keys的列表和计数,这些查询keys出现在不同的url中?
类似:
"buckets": [
{
"key": "/index.html",
"doc_count": 123456,
"query_key_count": {
"ab": 33456,
"cd": 3456,
"ef": 456,
"gh": 56,
"ij": 6
}
},
{
"key": "/hello.html",
"doc_count": 1456,
"query_key_count": {
"zy": 156,
"gh": 6
}
},
...
非常感谢!!
【问题讨论】:
-
您的意思是,query_key_count 实际上包含其键在数据中所有项目中出现的次数。假设您总共有 10 个对象,其中 2 个对象的 query 对象中有“ab”,那么您希望结果为 query_key_count:{"ab":2 。 .. 以此类推}?
-
这应该对你有帮助 >>> stackoverflow.com/questions/26743204/…
-
是的,如果我有一个带有参数“ab”和“cd”的 index.html-doc 和另一个带有随机值的参数“cd”和“ef”的 index.html-doc,我想得到一个“query_key_count”:{“cd”:2,“ab”:1,“ef”:1}。非常感谢您的链接 - 我会看看!
标签: elasticsearch