Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Count 弹性搜索。如何在一个查询中获取多个范围的计数?_Count_Group By_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Range - Fatal编程技术网 elasticsearch,range,Count,Group By,elasticsearch,Range" /> elasticsearch,range,Count,Group By,elasticsearch,Range" />

Count 弹性搜索。如何在一个查询中获取多个范围的计数?

Count 弹性搜索。如何在一个查询中获取多个范围的计数?,count,group-by,elasticsearch,range,Count,Group By,elasticsearch,Range,目前,我通过此查询获取一系列值的计数: $ curl -XGET 'http://localhost:9200/myindex/mytype/_count' -d '{ range:{myfield:{gt:"start_val",lt:"end_val"}} } ' 现在我有几个范围,每个范围都需要计数。我可以通过一次查询而不是每次重新查询来获取它们吗 我用search_type=count进行了调查,但可能这不是正确的方法。。。(它给了我一些聚合计数,而不是按……分组,看起来我误用

目前,我通过此查询获取一系列值的计数:

$ curl -XGET 'http://localhost:9200/myindex/mytype/_count' -d '{
    range:{myfield:{gt:"start_val",lt:"end_val"}}
}
'
现在我有几个范围,每个范围都需要计数。我可以通过一次查询而不是每次重新查询来获取它们吗

我用search_type=count进行了调查,但可能这不是正确的方法。。。(它给了我一些聚合计数,而不是按……分组,看起来我误用了它)

编辑:我发现这会令人惊讶,但不幸的是,我的值既不是数字,也不是日期,它们只是字符串

EDIT2:这是我根据接受的答案得出的结论:

$ curl -XGET 'http://localhost:9200/myindex/mytype/_search?search_type=count' -d '{
    facets : {
        range1 : {
            filter : {
                range:{myfield:{gt:"start_val1",lt:"end_val1"}}
            }
        },
        range2 : {
            filter : {
                range:{myfield:{gt:"start_val2",lt:"end_val2"}}
            }
        }
    }
}
'

这里有一个链接,ES的创建者提供了一个解决方案(即:多个过滤面)

因此,每个范围的一个过滤器面应该可以正常工作

以下是指向文档的链接:


希望能有所帮助

谢谢。根据你的回答,用我的答案更新了我的问题。很高兴我能帮上忙