There is no such thing as a perfect program, but that doesn’t discourage us, because writing a program is a constant pursuit of perfection.
Q: What are the features of collapse?
A:
– How will collapse be used?
A:
# collapse
PUT /collapse_test
{
"mappings" : {
"properties" : {
"name" : {"type" : "text"},
"user" : {
"properties": {
"id" : {"type" : "integer"},
"age" : {"type" : "integer"}}}}}} # index POST /collapse_test/_doc/1
{
"name" : "hello"."user" : {
"id" : 1."age" : 18}} # index POST /collapse_test/_doc/2
{
"name" : "hello good"."user" : {
"id" : 2."age" : 17}} # index POST /collapse_test/_doc/3
{
"name" : "hello good"."user" : {
"id" : 3."age" : 17}} # index POST /collapse_test/_doc/4
{
"name" : "hello good"."user" : {
"id" : 4."age" : 17}} # index POST /collapse_test/_doc/5
{
"name" : "hello good me"."user" : {
"id" : 5."age" : 19}} # Collapse_test /_search {"query" : {
"match" : {
"name" : "hello"}},"collapse" : {
"field" : "user.id"}} # result {"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# 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]}]}}}}]}} # collapse_test/_search {"collapse" : {
"field" : "user.age"."inner_hits" : {
"name" : "most_recent"."size" : 4."sort" : [{"user.id" : "desc"}]."collapse" : {
"field" : "user.id"}}}} # result {"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]}]}}}}]}}Copy the code