0

I followed the tutorial at the last part of this page.

POST /merchantindex/_search
{
    "function_score": {
    "query": {
    {"query_string": { "query": "test"}}
    },
    "functions": [
        {
            "script_score": 
            {
                "script": "return _score;"
            }
        }
    ]
}
}

What I am expecting the returning of relevance score. I wanted to do some processing with the _score, e.g. _score * some other stuffs but I am just trying if the code works for now.

Error that I got is

"error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed;...

1 Answer 1

1

This error:

"error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed;...

typically means that the formatting of your query is wrong.

if you check your query you'll see that you have two curly brackets between query and query_string:

"query": {    {"query_string":

Also function_score needs to sit inside a query and functions needs to be inside function_score.

Try this instead:

curl -XPOST "http://localhost:9200/merchantindex/_search" -d '
{
    "query": {
      "function_score" : {
         "query" :{
            "query_string": { "query": "test"}
         },
         "functions": [
         {
            "script_score": {
                "script": "return _score;"
            }
         }
       ]
     }
   }
}'
Sign up to request clarification or add additional context in comments.

2 Comments

I actually followed the code from some site, and I have tested your version and it is not functioning as well (same error). =(. Please advise.
How have you defined your script return_score? Can you add your full error message to your question?

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.