Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch Context Suggester geo context - boost without filtering?

I'm creating a completion suggester with a geo context (Elastic 5.x).

 mapping...
        "suggest": {
          "type": "completion",
          ...
          "contexts": [
          {
            "name": "geoloc",
            "type": "geo",
            "precision": 3,
            "path": "geolocation"
          }
        ]

When I query this, I'd like to have it not filter by the geo context, only boost results that are within the geohash. It works great to filter by a single geohash, or filter by a lower precision, and then boost a higher precision within that original filter like this:

GET /my-index/_search
{
  "suggest": {
      ...
      "completion": {
        "field": "suggest",
        "size": "10",
        "contexts": {
          "geoloc": [
            {
              "lat": 44.8214564,
              "lon": -93.475399,
              "precision": 1
            },
            {
              "lat": 44.8214564,
              "lon": -93.475399,
              "boost": 2
            }
          ]
        }
      }
  }
}

However, I can't get it to only boost on a single geo context without filtering. When I submit the following query, it filters and boosts:

GET /my-index/_search
{
  "suggest": {
      ...
      "completion": {
        "field": "suggest",
        "size": "10",
        "contexts": {
          "geoloc": [
            {
              "lat": 44.8214564,
              "lon": -93.475399,
              "boost": 2
            }
          ]
        }
      }
  }
}

Is what I'm trying to do just not supported, or am I missing something?

Thanks! Jason

like image 473
Jason Gott Avatar asked Oct 29 '22 21:10

Jason Gott


1 Answers

Just ran into this issue as well.

The solution I came up with through trial and error was to use the category context to filter first to all my documents. Say you had added a category to your documents named "all" you could do this:

GET /my-index/_search
{
  "suggest": {
      ...
      "completion": {
        "field": "suggest",
        "size": "10",
        "contexts": {
          "category": ["all"],
          "geoloc": [
            {
              "lat": 44.8214564,
              "lon": -93.475399,
              "precision": 2,
              "boost": 2
            }
          ]
        }
      }
  }
}

When this is done, it seems to be selecting everything with the "all" category and then boosts the ones within the precision level specified to the top.

Using Elastic 6.*

like image 136
daamsie Avatar answered Nov 15 '22 09:11

daamsie