query malformed, no start_object after query name
Asked Answered
R

1

24

I am running this query against AWS Elasticsearch 5.1 and getting a malformed query error. Here is the body of the request. I am basically just checking if the field exists during the time range.

{
  "query": {
    "bool": {
      "filter": {
        "bool": {
          "must": [
            {
              "range": {
                "@timestamp": {
                  "gt": "2017-03-21T15:37:08.595919Z",
                  "lte": "2017-04-21T15:52:08.595919Z"
                }
              }
            },
            {
              "query": [
                {
                  "query_string": {
                    "query": "_exists_: $event.supplier"
                  }
                }
              ]
            }
          ]
        }
      }
    }
  },
  "sort": [
    {
      "@timestamp": {
        "order": "asc"
      }
    }
  ]
}
Ralfston answered 21/4, 2017 at 16:43 Comment(0)
M
21

The second must statement was incorrect:

{
  "query": {
    "bool": {
      "filter": {
        "bool": {
          "must": [
            {
              "range": {
                "@timestamp": {
                  "gt": "2017-03-21T15:37:08.595919Z",
                  "lte": "2017-04-21T15:52:08.595919Z"
                }
              }
            },
            {
              "query_string": {
                "query": "_exists_: $event.supplier"
              }
            }
          ]
        }
      }
    }
  },
  "sort": [
    {
      "@timestamp": {
        "order": "asc"
      }
    }
  ]
}
Maud answered 21/4, 2017 at 22:4 Comment(7)
where on the earth the second must statement is?Wsan
Having diffed the answer, they've removed the query specifier that used to be around query_stringMceachern
For those coming here in the future: The must is an array, so the second set of curly braces that holds the query_string is the second must.Masquerade
so it was the second item in the must arrayBurgess
@tar there is nothing to explain. The original query was malformed, which means that there was a syntax error in it. No error in the logic of the query of how it was created, just a syntax error. I've corrected the error and posted the correct query. If you compare the two you'll notice the difference. Downvoting a correct answer with an explanation like that is unfair. I hope you'll find my other answers on the Elasticsearch subject more useful to you.Maud
@AndreiStefan can you also explain the error "no start_object after query name", what on earth does it mean? in this case what exactly is a "start_object" and what are the possible things/keywords that could be a start_object?Atwitter
@ThomasNguyen in JSON format { } is considered an "object". Start of an object is the opening curly bracket. no start_object after query name means the JSON parser is expecting an opening curly bracket after the "query name".Maud

© 2022 - 2024 — McMap. All rights reserved.