3

I am trying to run a straight forward Function Score Query in elasticsearch as:

{
"function_score": {
  "query": {
     "term": {
        "timestamp": {
           "value": 1396361509,
           "boost": 0.05
        }
     }
  },
  "script_score": {
     "script": "abs(1396361509 - doc['timestamp'].value)"
  }
}
}

but I keep getting an error saying that there is no parser for "function_score":

 SearchParseException[[test_index][4]: from[-1],size[-1]: Parse Failure [No parser for element [function_score]]]; }{[PKoYz4OLTbOWb6ziP8AIaQ][test_index][1]: SearchParseException[[test_index][1]: from[-1],size[-1]: Parse Failure [Failed to parse source

I am using elasticsearch 1.1.1 and tried running it via curl call, from elastic-head, and via a JAVA API. Results are always the same!

6
  • It seems you've cut off your error message. Can you please edit the question and post the full error message. Commented May 5, 2014 at 14:51
  • The rest of the message just continues with the query. Commented May 5, 2014 at 15:42
  • 1
    SOLVED -- function score needs to be wrapped in another query. A bit strange I find! Commented May 5, 2014 at 15:45
  • Please write up a quick answer with your example fixed and select it as the right answer so others can easily find it Commented May 5, 2014 at 15:48
  • added in the main question! Commented May 6, 2014 at 12:27

1 Answer 1

3

Disclaimer: This was extracted from the question

The function score should itself be wrapped in a query! Here is an example:

  {
    "query": { 
      "bool" : {
        "should" : {
          "function_score" : {
                     "query" : {
          "match_all" : { }
        },
        "script_score" : {
          "script" : "_score * 1/abs(1396361509-doc['timestamp'].value)"
        }
      }
    },
    "boost" : 0.05
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.