1

How would I construct an ElasticSearch query to satisfy the following:

Price must be between 100,000 & 200,000, but also show results outside of this range, but with decreasing relevance if above 200k or below 100k.

So far I have the following but it doesn't seem to be doing what I want (omitted the wrapping query for brevity):

"function_score": {
        "query": {
          "range": {
            "price_amount": {
              "gte": 100000,
              "lte": 200000
            }
          }
        },
        "functions": [
          {
            "gauss": {
              "price_amount": {
                "origin": "50000",
                "offset": "50000",
                "scale": "10000"
              }
            }
          }
        ]
      }

Update:

Had another look and I think setting the function to the following, without the range query would do the trick, wouldn't it?

"function_score": {
        "functions": [
          {
            "gauss": {
              "price_amount": {
                "origin": "150000",
                "offset": "50000",
                "scale": "10000"
              }
            }
          }
        ]
      }

Many thanks! Lee

Lee Overy
  • 437
  • 5
  • 13
  • You might be interested in option C from the following answer: http://stackoverflow.com/questions/35165029/with-elasticsearch-function-score-query-with-decay-against-a-geo-point-is-it-po/35193017#35193017 – Val Jun 27 '16 at 14:03
  • Thanks @Val but Im still a little uncertain how I would apply that with the price range above. – Lee Overy Jun 28 '16 at 08:03
  • How would you combine both though? For example, if you want a certain range but want to score higher those closer to the origin? – radtek Nov 07 '17 at 16:21

0 Answers0