Skip to content

rebalance fallback.venue queries #1491

@missinglink

Description

@missinglink

I was testing #1380 today and found this bug related to venue queries with the /v1/search API.

Given the following parse:

"parser": "libpostal",
"parsed_text": {
  "query": "target",
  "city": "eureka",
  "state": "ca"
}

The following query is generated (pasted at the end for brevity)

We can see that many results were returned from ES:

{
   "search_fallback":{
      "es_took":229,
      "response_time":233,
      "retries":0,
      "es_hits":44,
      "es_result_count":20
   }
}

but the results are:

0) Eureka, CA, USA
1) Plumas Eureka, CA, USA

when they should be:

1) Target, Eureka, CA, USA

When I ran the ES query manually I found that all of the top results are coming from the admin layers:

"fallback.region"
"fallback.locality"
"fallback.locality"
"fallback.region"
"fallback.locality"
"fallback.locality"
"fallback.locality"
"fallback.region"
"fallback.region"
"fallback.region"
"fallback.region"
"fallback.region"
"fallback.region"
"fallback.region"
"fallback.region"
"fallback.region"
"fallback.region"
"fallback.region"
"fallback.region"
"fallback.region"

What I suspect is happening here is that the population scoring is increasing the scores for administrative places much higher than those for venues, meaning that the venue results are not returned.

We can probably fix this by applying a boost to the fallback.venue clause so that it can compete with the high scores generated by admin matches:

# scores corresponding to the admin fallback matches listed directly above

"_score": 47.895332,
"_score": 44.888824,
"_score": 44.842762,
"_score": 39.021828,
"_score": 22.350563,
"_score": 22.343859,
"_score": 22.316488,
"_score": 19.958286,
"_score": 19.931473,
"_score": 16.801222,
"_score": 16.78785,
"_score": 16.157461,
"_score": 16.063375,
"_score": 15.326169,
"_score": 15.228479,
"_score": 15.188125,
"_score": 15.156264,
"_score": 15.089676,
"_score": 15.087963,
"_score": 15.082789,
{
   "function_score":{
      "query":{
         "bool":{
            "minimum_should_match":1,
            "should":[
               {
                  "bool":{
                     "_name":"fallback.venue",
                     "must":[
                        {
                           "multi_match":{
                              "query":"target",
                              "type":"phrase",
                              "fields":[
                                 "phrase.default"
                              ]
                           }
                        },
                        {
                           "multi_match":{
                              "query":"eureka",
                              "type":"phrase",
                              "fields":[
                                 "parent.locality",
                                 "parent.locality_a",
                                 "parent.localadmin",
                                 "parent.localadmin_a"
                              ]
                           }
                        },
                        {
                           "multi_match":{
                              "query":"ca",
                              "type":"phrase",
                              "fields":[
                                 "parent.region",
                                 "parent.region_a",
                                 "parent.macroregion",
                                 "parent.macroregion_a"
                              ]
                           }
                        }
                     ],
                     "filter":{
                        "term":{
                           "layer":"venue"
                        }
                     }
                  }
               },
               {
                  "bool":{
                     "_name":"fallback.locality",
                     "must":[
                        {
                           "multi_match":{
                              "query":"eureka",
                              "type":"phrase",
                              "fields":[
                                 "parent.locality",
                                 "parent.locality_a"
                              ]
                           }
                        },
                        {
                           "multi_match":{
                              "query":"ca",
                              "type":"phrase",
                              "fields":[
                                 "parent.region",
                                 "parent.region_a",
                                 "parent.macroregion",
                                 "parent.macroregion_a"
                              ]
                           }
                        }
                     ],
                     "filter":{
                        "term":{
                           "layer":"locality"
                        }
                     }
                  }
               },
               {
                  "bool":{
                     "_name":"fallback.localadmin",
                     "must":[
                        {
                           "multi_match":{
                              "query":"eureka",
                              "type":"phrase",
                              "fields":[
                                 "parent.localadmin",
                                 "parent.localadmin_a"
                              ]
                           }
                        },
                        {
                           "multi_match":{
                              "query":"ca",
                              "type":"phrase",
                              "fields":[
                                 "parent.region",
                                 "parent.region_a",
                                 "parent.macroregion",
                                 "parent.macroregion_a"
                              ]
                           }
                        }
                     ],
                     "filter":{
                        "term":{
                           "layer":"localadmin"
                        }
                     }
                  }
               },
               {
                  "bool":{
                     "_name":"fallback.region",
                     "must":[
                        {
                           "multi_match":{
                              "query":"ca",
                              "type":"phrase",
                              "fields":[
                                 "parent.region",
                                 "parent.region_a"
                              ]
                           }
                        }
                     ],
                     "filter":{
                        "term":{
                           "layer":"region"
                        }
                     }
                  }
               },
               {
                  "bool":{
                     "_name":"fallback.macroregion",
                     "must":[
                        {
                           "multi_match":{
                              "query":"ca",
                              "type":"phrase",
                              "fields":[
                                 "parent.macroregion",
                                 "parent.macroregion_a"
                              ]
                           }
                        }
                     ],
                     "filter":{
                        "term":{
                           "layer":"macroregion"
                        }
                     }
                  }
               }
            ],
            "filter":{
               "bool":{
                  "must":[
                     {
                        "terms":{
                           "layer":[
                              "venue",
                              "street",
                              "country",
                              "macroregion",
                              "region",
                              "county",
                              "localadmin",
                              "locality",
                              "borough",
                              "neighbourhood",
                              "continent",
                              "empire",
                              "dependency",
                              "macrocounty",
                              "macrohood",
                              "microhood",
                              "disputed",
                              "postalcode",
                              "ocean",
                              "marinearea"
                           ]
                        }
                     }
                  ]
               }
            }
         }
      },
      "max_boost":20,
      "functions":[
         {
            "field_value_factor":{
               "modifier":"log1p",
               "field":"popularity",
               "missing":1
            },
            "weight":1
         },
         {
            "field_value_factor":{
               "modifier":"log1p",
               "field":"population",
               "missing":1
            },
            "weight":2
         }
      ],
      "score_mode":"avg",
      "boost_mode":"multiply"
   }
}

note: the feature branch will unlikely still be on dev when you click this link ;)
https://pelias.github.io/compare/#/v1/search?text=Target+Eureka+CA&debug=1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions