查询动态聚合在elasticsearch与AJAX [英] Querying dynamic aggregation in elasticsearch with AJAX
本文介绍了查询动态聚合在elasticsearch与AJAX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图建立动态的基础上一组字段的查询使用映射的集合。 这里的code。
I'm trying to build an aggregation dynamically based on a group of fields queried using the mapping. Here's the code.
$(document).ready(function(){
var query = {
aggs:{
sum_of_too_many_tries:{
sum:{
field:"reason.too_many_tries"
}
}
}
};
$.ajax({
url: "http://10.138.16.125:9200/log/blocks/_mapping",
type: "get",
async: false,
crossDomain: true,
success: function(data) {
var fields = Object.keys(data.log.mappings.blocks.properties.reasons.properties);
$.ajax({
url: "http://10.138.16.125:9200/log/blocks/_search",
crossDomain: true,
async: false,
type: "get",
dataType: "json",
data: JSON.stringify(query),
success: function(response) {
$("#dump").append(var_dump(response));
}
});
}
});
});
当我做了查询,它返回命中正常,无聚集。我究竟做错了什么?
When I do the query, it returns the hits normally, without the aggregations. What am I doing wrong?
如果你需要更多的code,只问。
If you need more code, just ask.
推荐答案
您需要发送的查询作为POST而不是GET。 当您发送它为GET,但是你打了_search API,不考虑查询的一部分。因此,你只会得到的前N个文件列的索引。
You need to sent your query as POST rather than GET. When you are sending it as GET , though you are hitting the _search API , the query part is not considered. Hence you will just get the top N documents out of the index.
这篇关于查询动态聚合在elasticsearch与AJAX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文