Unknown key for a START_OBJECT in [should]

Hi all,

Still brand new to ElasticSearch (and JSON for that matter). I get this error:

{
    "error": {
        "root_cause": [
            {
                "type": "parsing_exception",
                "reason": "Unknown key for a START_OBJECT in [should].",
                "line": 19,
                "col": 4
            }
        ],
        "type": "parsing_exception",
        "reason": "Unknown key for a START_OBJECT in [should].",
        "line": 19,
        "col": 4
    },
    "status": 400
}

When making this call to my ElasticSearch Index:

{
   "size": 150,
   "query": {
      "bool": {
         "must": {
            "nested": {
               "path": "entities",
               "query": {
                  "match": {
                     "entities.name": "donald trump"
                  }
               }
            }
         }
      }
   },

   "should":
   {
      "nested": {
         "path": "entities",
         "query": {
            "match_phrase": {
               "entities.name": {
                  "query": "donald trump",
                  "slop": 5
               }
            }
         }
      }
   },
  
   "rescore": {
      "window_size": 2000,
      "query": {
         "score_mode": "max",
         "rescore_query": {
            "nested": {
               "path": "entities",
               "score_mode": "max",
               "query": {
                  "function_score": {
                     "doc_score": {
                        "field": "entities.name",
                        "query_value": "donald trump"
                     }
                  }
               }
            }
         }
      }
   },
   "query_weight": 0,
   "rescore_query_weight": 1
}

Would someone be kind enough to guide me on correcting this error, as well as let me know if you see anything else in this query that I need to correct?

Many thanks!

Bump. If anyone can point me in the right direction I'd be very appreciative. I'm unfortunately holding up some progress on my team until I can figure this out.

From the ES forum about post:

Please see the code of conduct 171 for more details on our code of conduct (in particular the "be patient" section).

Bumping your own post after 1 day (over a weekend!) suggests that you have unrealistic expectations about the level of support we are able to provide in these forums.

This error is saying (somewhat cryptically) that you have a key "should" with an Object value, in place where that key isn't recognised.

The specific cause here is that your "should" needs to be part of your "bool" query, not part of the _search body.

Hi Tim, sorry about that and understood. I'm new here, but not new to forums so I can't claim total ignorance on the subject. Thanks for the heads-up.

Thanks for the reply, Tim. I can see now how the Should is outside of the bool. Thanks so much!!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.