Я пытаюсь запросить и отсортировать результаты поиска по весу документов,
Я использовал следующие запросы для создания и запроса данных,
Версия ElasticSearch: 7.6,
Версия Kibana: 7.2
DELETE movies
PUT movies
{
"mappings": {
"properties": {
"name": {
"type": "completion"
},
"year": {
"type": "keyword"
}
}
}
}
POST _bulk
{ "index" : { "_index" : "movies", "_id" : "1" } }
{ "name" : "Spider-Man: Far From Home", "year" : "2019"}
{ "index" : { "_index" : "movies", "_id" : "2" } }
{ "name" : "Avengers: Endgame" , "year" : "2019"}
{ "index" : { "_index" : "movies", "_id" : "3" } }
{ "name" : "Captain Marvel" , "year" : "2019"}
{ "index" : { "_index" : "movies", "_id" : "4" } }
{ "name" : "Ant-man and the Wasp" , "year" : "2018" }
{ "index" : { "_index" : "movies", "_id" : "5" } }
{ "name" : "Avengers: Infinity War" , "year" : "2018" }
{ "index" : { "_index" : "movies", "_id" : "6" } }
{ "name" : "Black Panther" , "year" : "2018" }
{ "index" : { "_index" : "movies", "_id" : "7" } }
{ "name" : "Thor: Ragnarok" , "year" : "2017" }
{ "index" : { "_index" : "movies", "_id" : "8" } }
{ "name" : "Spider-Man: Homecoming" , "year" : "2017" }
{ "index" : { "_index" : "movies", "_id" : "9" } }
{ "name" : "Guardians of the Galaxy Vol 2" , "year" : "2017" }
{ "index" : { "_index" : "movies", "_id" : "10" } }
{ "name" : "Doctor Strange" , "year" : "2016" }
{ "index" : { "_index" : "movies", "_id" : "11" } }
{ "name" : "Guardians of the Galaxy Vol 2" , "year" : "2019"}
{ "index" : { "_index" : "movies", "_id" : "12" } }
{ "name" : "Captain America: Civil War" , "year" : "2016"}
{ "index" : { "_index" : "movies", "_id" : "13" } }
{ "name" : "Ant-Man" , "year" : "2015" }
{ "index" : { "_index" : "movies", "_id" : "14" } }
{ "name" : "Avengers: Age of Ultron" , "year" : "2015"}
{ "index" : { "_index" : "movies", "_id" : "15" } }
{ "name" : "Guardians of the Galaxy" , "year" : "2014" }
{ "index" : { "_index" : "movies", "_id" : "16" } }
{ "name" : "Captain America: The Winter Soldier" , "year" : "2014" }
{ "index" : { "_index" : "movies", "_id" : "17" } }
{ "name" : "Thor: The Dark World" , "year" : "2013" }
{ "index" : { "_index" : "movies", "_id" : "18" } }
{ "name" : "Iron Man 3" ,"year" : "2013" }
{ "index" : { "_index" : "movies", "_id" : "19" } }
{ "name" : "Marvel's The Avengers" , "year" : "2012"}
{ "index" : { "_index" : "movies", "_id" : "20" } }
{ "name" : "Captain America: The First Avenger" , "year" : "2011"}
{ "index" : { "_index" : "movies", "_id" : "21" } }
{ "name" : "Thor" , "year" : "2011"}
{ "index" : { "_index" : "movies", "_id" : "22" } }
{ "name" : "Iron Man 2", "year" : "2010" }
{ "index" : { "_index" : "movies", "_id" : "23" } }
{ "name" : "The Incredible Hulk", "year" : "2008" }
{ "index" : { "_index" : "movies", "_id" : "24" } }
{ "name" : "Iron Man" , "year" : "2008"}
PUT movies/_doc/22
{
"name": {
"input": ["Iron Man 2"],
"weight": 2
},
"year": 2010
}
GET movies/_search
{
"query": {
"match": {
"name": "iron man"
}
}
}
Я получаю следующий вывод -
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 3,
"relation" : "eq"
},
"max_score" : 1.754019,
"hits" : [
{
"_index" : "movies",
"_type" : "_doc",
"_id" : "18",
"_score" : 1.754019,
"_source" : {
"name" : "Iron Man 3",
"year" : "2013"
}
},
{
"_index" : "movies",
"_type" : "_doc",
"_id" : "24",
"_score" : 1.754019,
"_source" : {
"name" : "Iron Man",
"year" : "2008"
}
},
{
"_index" : "movies",
"_type" : "_doc",
"_id" : "22",
"_score" : 1.754019,
"_source" : {
"name" : {
"input" : [
"Iron Man 2"
],
"weight" : 2
},
"year" : 2010
}
}
]
}
}
Мой ожидаемый результат - Iron Man 2
, идущий сверху, так как его вес выше,
Как мне добиться этого с помощью запроса?