本文主要是介绍es - elasticsearch search - collapse,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程。
问 :collapse有什么特点?
答 :
问 :collapse如何使用?
答 :
# collapse
PUT /collapse_test
{"mappings" : {"properties" : {"name" : {"type" : "text"},"user" : {"properties": { "id" : {"type" : "integer"},"age" : {"type" : "integer"}}}}}
}# 索引
POST /collapse_test/_doc/1
{"name" : "hello","user" : {"id" : 1,"age" : 18}
}# 索引
POST /collapse_test/_doc/2
{"name" : "hello good","user" : {"id" : 2,"age" : 17}
}# 索引
POST /collapse_test/_doc/3
{"name" : "hello good","user" : {"id" : 3,"age" : 17}
}# 索引
POST /collapse_test/_doc/4
{"name" : "hello good","user" : {"id" : 4,"age" : 17}
}# 索引
POST /collapse_test/_doc/5
{"name" : "hello good me","user" : {"id" : 5,"age" : 19}
}# 搜索
GET /collapse_test/_search
{"query" : {"match" : {"name" : "hello"}},"collapse" : {"field" : "user.id"}
}# 结果
{"took" : 0,"timed_out" : false,"_shards" : {"total" : 1,"successful" : 1,"skipped" : 0,"failed" : 0},"hits" : {"total" : {"value" : 5,"relation" : "eq"},"max_score" : null,"hits" : [{"_index" : "collapse_test","_type" : "_doc","_id" : "1","_score" : 0.10938574,"_source" : {"name" : "hello","user" : {"id" : 1,"age" : 18}},"fields" : {"user.id" : [1]}},{"_index" : "collapse_test","_type" : "_doc","_id" : "2","_score" : 0.08701137,"_source" : {"name" : "hello good","user" : {"id" : 2,"age" : 17}},"fields" : {"user.id" : [2]}},{"_index" : "collapse_test","_type" : "_doc","_id" : "3","_score" : 0.08701137,"_source" : {"name" : "hello good","user" : {"id" : 3,"age" : 17}},"fields" : {"user.id" : [3]}},{"_index" : "collapse_test","_type" : "_doc","_id" : "4","_score" : 0.08701137,"_source" : {"name" : "hello good","user" : {"id" : 4,"age" : 17}},"fields" : {"user.id" : [4]}},{"_index" : "collapse_test","_type" : "_doc","_id" : "5","_score" : 0.07223585,"_source" : {"name" : "hello good me","user" : {"id" : 5,"age" : 19}},"fields" : {"user.id" : [5]}}]}
}# 搜索
GET /collapse_test/_search
{"collapse" : {"field" : "user.age","inner_hits" : [{"name" : "most_recent","size" : 4,"sort" : [{"user.id" : "desc"}]},{"name" : "largest_responses","size" : 4,"sort" : [{"user.id" : "asc"}]}],"max_concurrent_group_searches" : 4},"sort" : [{"user.id" : "desc"}]
}# 结果
{"took" : 0,"timed_out" : false,"_shards" : {"total" : 1,"successful" : 1,"skipped" : 0,"failed" : 0},"hits" : {"total" : {"value" : 5,"relation" : "eq"},"max_score" : null,"hits" : [{"_index" : "collapse_test","_type" : "_doc","_id" : "5","_score" : null,"_source" : {"name" : "hello good me","user" : {"id" : 5,"age" : 19}},"fields" : {"user.age" : [19]},"sort" : [5],"inner_hits" : {"most_recent" : {"hits" : {"total" : {"value" : 1,"relation" : "eq"},"max_score" : null,"hits" : [{"_index" : "collapse_test","_type" : "_doc","_id" : "5","_score" : null,"_source" : {"name" : "hello good me","user" : {"id" : 5,"age" : 19}},"sort" : [5]}]}},"largest_responses" : {"hits" : {"total" : {"value" : 1,"relation" : "eq"},"max_score" : null,"hits" : [{"_index" : "collapse_test","_type" : "_doc","_id" : "5","_score" : null,"_source" : {"name" : "hello good me","user" : {"id" : 5,"age" : 19}},"sort" : [5]}]}}}},{"_index" : "collapse_test","_type" : "_doc","_id" : "4","_score" : null,"_source" : {"name" : "hello good","user" : {"id" : 4,"age" : 17}},"fields" : {"user.age" : [17]},"sort" : [4],"inner_hits" : {"most_recent" : {"hits" : {"total" : {"value" : 3,"relation" : "eq"},"max_score" : null,"hits" : [{"_index" : "collapse_test","_type" : "_doc","_id" : "4","_score" : null,"_source" : {"name" : "hello good","user" : {"id" : 4,"age" : 17}},"sort" : [4]},{"_index" : "collapse_test","_type" : "_doc","_id" : "3","_score" : null,"_source" : {"name" : "hello good","user" : {"id" : 3,"age" : 17}},"sort" : [3]},{"_index" : "collapse_test","_type" : "_doc","_id" : "2","_score" : null,"_source" : {"name" : "hello good","user" : {"id" : 2,"age" : 17}},"sort" : [2]}]}},"largest_responses" : {"hits" : {"total" : {"value" : 3,"relation" : "eq"},"max_score" : null,"hits" : [{"_index" : "collapse_test","_type" : "_doc","_id" : "2","_score" : null,"_source" : {"name" : "hello good","user" : {"id" : 2,"age" : 17}},"sort" : [2]},{"_index" : "collapse_test","_type" : "_doc","_id" : "3","_score" : null,"_source" : {"name" : "hello good","user" : {"id" : 3,"age" : 17}},"sort" : [3]},{"_index" : "collapse_test","_type" : "_doc","_id" : "4","_score" : null,"_source" : {"name" : "hello good","user" : {"id" : 4,"age" : 17}},"sort" : [4]}]}}}},{"_index" : "collapse_test","_type" : "_doc","_id" : "1","_score" : null,"_source" : {"name" : "hello","user" : {"id" : 1,"age" : 18}},"fields" : {"user.age" : [18]},"sort" : [1],"inner_hits" : {"most_recent" : {"hits" : {"total" : {"value" : 1,"relation" : "eq"},"max_score" : null,"hits" : [{"_index" : "collapse_test","_type" : "_doc","_id" : "1","_score" : null,"_source" : {"name" : "hello","user" : {"id" : 1,"age" : 18}},"sort" : [1]}]}},"largest_responses" : {"hits" : {"total" : {"value" : 1,"relation" : "eq"},"max_score" : null,"hits" : [{"_index" : "collapse_test","_type" : "_doc","_id" : "1","_score" : null,"_source" : {"name" : "hello","user" : {"id" : 1,"age" : 18}},"sort" : [1]}]}}}}]}
}# 搜索,二级折叠
GET /collapse_test/_search
{"collapse" : {"field" : "user.age","inner_hits" : {"name" : "most_recent","size" : 4,"sort" : [{"user.id" : "desc"}],"collapse" : {"field" : "user.id"}}}
}# 结果
{"took" : 0,"timed_out" : false,"_shards" : {"total" : 1,"successful" : 1,"skipped" : 0,"failed" : 0},"hits" : {"total" : {"value" : 5,"relation" : "eq"},"max_score" : null,"hits" : [{"_index" : "collapse_test","_type" : "_doc","_id" : "1","_score" : 1.0,"_source" : {"name" : "hello","user" : {"id" : 1,"age" : 18}},"fields" : {"user.age" : [18]},"inner_hits" : {"most_recent" : {"hits" : {"total" : {"value" : 1,"relation" : "eq"},"max_score" : null,"hits" : [{"_index" : "collapse_test","_type" : "_doc","_id" : "1","_score" : null,"_source" : {"name" : "hello","user" : {"id" : 1,"age" : 18}},"fields" : {"user.id" : [1]},"sort" : [1]}]}}}},{"_index" : "collapse_test","_type" : "_doc","_id" : "2","_score" : 1.0,"_source" : {"name" : "hello good","user" : {"id" : 2,"age" : 17}},"fields" : {"user.age" : [17]},"inner_hits" : {"most_recent" : {"hits" : {"total" : {"value" : 3,"relation" : "eq"},"max_score" : null,"hits" : [{"_index" : "collapse_test","_type" : "_doc","_id" : "4","_score" : null,"_source" : {"name" : "hello good","user" : {"id" : 4,"age" : 17}},"fields" : {"user.id" : [4]},"sort" : [4]},{"_index" : "collapse_test","_type" : "_doc","_id" : "3","_score" : null,"_source" : {"name" : "hello good","user" : {"id" : 3,"age" : 17}},"fields" : {"user.id" : [3]},"sort" : [3]},{"_index" : "collapse_test","_type" : "_doc","_id" : "2","_score" : null,"_source" : {"name" : "hello good","user" : {"id" : 2,"age" : 17}},"fields" : {"user.id" : [2]},"sort" : [2]}]}}}},{"_index" : "collapse_test","_type" : "_doc","_id" : "5","_score" : 1.0,"_source" : {"name" : "hello good me","user" : {"id" : 5,"age" : 19}},"fields" : {"user.age" : [19]},"inner_hits" : {"most_recent" : {"hits" : {"total" : {"value" : 1,"relation" : "eq"},"max_score" : null,"hits" : [{"_index" : "collapse_test","_type" : "_doc","_id" : "5","_score" : null,"_source" : {"name" : "hello good me","user" : {"id" : 5,"age" : 19}},"fields" : {"user.id" : [5]},"sort" : [5]}]}}}}]}
}
这篇关于es - elasticsearch search - collapse的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!