我遇到了一个问题,即弹性搜索无法通过在嵌套字段上使用术语聚合来返回唯一文档的数量.
这是我们模型的一个例子:
{
...,
"location" : [
{"city" : "new york", "state" : "ny"},
{"city" : "woodbury", "state" : "ny"},
...
],
...
}
Run Code Online (Sandbox Code Playgroud)
我想在状态字段上进行聚合,但是这个文档将在'ny'桶中计数两次,因为'ny'在文档中出现两次.
所以我想知道在哪里可以获取不同文档的数量.
制图:
people = {
:properties => {
:location => {
:type => 'nested',
:properties => {
:city => {
:type => 'string',
:index => 'not_analyzed',
},
:state => {
:type => 'string',
:index => 'not_analyzed',
},
}
},
:last_name => {
:type => 'string',
:index => 'not_analyzed'
}
}
}
Run Code Online (Sandbox Code Playgroud)
查询非常简单:
curl -XGET 'http://localhost:9200/people/_search?pretty&search_type=count' …Run Code Online (Sandbox Code Playgroud) 我有一个这样的方法:
def make_request(path, params, body)
raise ArgumentError.new('Endpoint not set!') if url.nil?
conditions = {url: url}
conditions[:params] = params unless params.blank?
connection = Faraday::Connection.new(conditions)
connection.run_request(:get, path, body, {'Content-Type' => 'application/json'})
end
Run Code Online (Sandbox Code Playgroud)
那我该如何添加 keep-alive 呢?另外,由于我每次调用此方法时都会实例化一个连接对象(url 可能不同),所以 keep-alive 参数仍然有效吗?
目前我遇到了一个奇怪的问题:当我根据字段排序时,它会抛出异常:
curl -XGET 'http://localhost:9200/pb/p/_search?pretty' -d '{
"query": {"match" : {"first_name" : "john"}},
"sort" : {
"_script" : {
"script" : "doc['dob_size'].value * factor1",
"type" : "number",
"params" : {"factor1" : 1},
"order" : "desc"
}}}'
{
"took" : 5,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 1,
"failed" : 4,
"failures" : [ {
"index" : "pb",
"shard" : 0,
"status" : 500,
"reason" : "QueryPhaseExecutionException[[pb][0]: query[filtered(first_name:john)->cache(_type:p)],from[0],size[10],sort[<custom:\"_script\": org.elasticsearch.search.sort.ScriptSortParser$2@7ac5f844>!]: Query Failed [Failed to execute main query]]; nested: …Run Code Online (Sandbox Code Playgroud)