Searching then sorting in a multi-indices search

Hi,
I am trying to create a general search on my site that users can start typing in a name and it will search three indices, an event, an organizer and a city list. Currently I have

GET /events,city_lists,organizers/_search
{
  "query": {
    "multi_match" : {
      "query":    "los angeles", 
      "type":       "bool_prefix",
      "fields": [ "name", "name._2gram","name._3gram" ]
    }
  }
}

this works and delivers los angeles back first. However, I want city_lists to be my lowest priority so if the user types in chaos

GET /events,city_lists,organizers/_search
{
  "query": {
    "multi_match" : {
      "query":    "chaos", 
      "type":       "bool_prefix",
      "fields": [ "name", "name._2gram","name._3gram" ]
    }
  }
}

it returns

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 3,
    "successful" : 3,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 5,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "city_lists",
        "_type" : "_doc",
        "_id" : "88311",
        "_score" : 1.0,
        "_source" : {
          "name" : "Chaohu, CN",
          "population" : 138463,
          "rank" : 10,
          "priority" : 1
        }
      },
      {
        "_index" : "city_lists",
        "_type" : "_doc",
        "_id" : "88312",
        "_score" : 1.0,
        "_source" : {
          "name" : "Chaoyang, CN",
          "population" : 75347,
          "rank" : 10,
          "priority" : 1
        }
      },
      {
        "_index" : "city_lists",
        "_type" : "_doc",
        "_id" : "88313",
        "_score" : 1.0,
        "_source" : {
          "name" : "Chaoyang, CN",
          "population" : 410005,
          "rank" : 10,
          "priority" : 1
        }
      },
      {
        "_index" : "city_lists",
        "_type" : "_doc",
        "_id" : "88314",
        "_score" : 1.0,
        "_source" : {
          "name" : "Chaozhou, CN",
          "population" : 424787,
          "rank" : 10,
          "priority" : 1
        }
      },
      {
        "_index" : "events",
        "_type" : "_doc",
        "_id" : "75",
        "_score" : 1.0,
        "_source" : {
          "name" : "Chaos Theory",
          "status" : "p",
          "showtype" : "s",
          "rank" : 4,
          "category_id" : 3,
          "location_latlon" : null,
          "hasLocation" : false,
          "shows" : [
            {
              "date" : "2020-08-06 00:00:00"
            },
            {
              "date" : "2020-09-03 00:00:00"
            },
            {
              "date" : "2020-10-01 00:00:00"
            },
            {
              "date" : "2020-11-05 00:00:00"
            },
            {
              "date" : "2020-12-03 00:00:00"
            }
          ],
          "published_at" : "2020-06-23 18:10:57",
          "closingDate" : "2020-12-03 00:00:00",
          "priceranges" : [
            {
              "price" : "25.00"
            },
            {
              "price" : "12.00"
            }
          ],
          "genres" : [
            {
              "name" : "Comedy",
              "pivot" : {
                "event_id" : 75,
                "genre_id" : 7
              }
            },
            {
              "name" : "Immersive",
              "pivot" : {
                "event_id" : 75,
                "genre_id" : 1
              }
            },
            {
              "name" : "Intimate",
              "pivot" : {
                "event_id" : 75,
                "genre_id" : 12
              }
            },
            {
              "name" : "Participatory",
              "pivot" : {
                "event_id" : 75,
                "genre_id" : 23
              }
            },
            {
              "name" : "Remote",
              "pivot" : {
                "event_id" : 75,
                "genre_id" : 10
              }
            },
            {
              "name" : "Zoom",
              "pivot" : {
                "event_id" : 75,
                "genre_id" : 16
              }
            }
          ],
          "priority" : 5
        }
      }
    ]
  }
}

As you can see the event is number 5 and the cities that arent even spelled the same as chaos are returning above the event. I was hoping to fix this using priority

GET /events,city_lists,organizers/_search
{
  "query": {
    "multi_match" : {
      "query":    "los angeles", 
      "type":       "bool_prefix",
      "sort": [
          { "priority" : {"order" : "desc"} }
        ],
      "fields": [ "name", "name._2gram","name._3gram" ]
    }
  }
}

but this gives me the error

"reason" : "[multi_match] unknown token [START_ARRAY] after [sort]",

How so I set it up so a user gets shown events with the highest priority, then organizers and finally city_lists when searching across multiple indices and still have a similar search as you type results returned?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.