Home > Mobile >  Getting error when search for query [match] malformed query, expected [END_OBJECT] but found [FIELD_
Getting error when search for query [match] malformed query, expected [END_OBJECT] but found [FIELD_

Time:09-26

I'm using postman and try to search for a query plus use the range date but I get an error that says its malformed query, can you please help me.

The error:

{
    "error": {
        "root_cause": [
            {
                "type": "parsing_exception",
                "reason": "[match] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
                "line": 8,
                "col": 5
            }
        ],
        "type": "parsing_exception",
        "reason": "[match] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
        "line": 8,
        "col": 5
    },
    "status": 400
}

the body query:

{  "query": {
        "match": {
            "category": {
                "query": "الأنظمة",
                "operator": "and"
            }
        },
    "range": {
      "date": {
        "gte": "1970-01-01",
        "lt": "2400-01-01"
      }
    }
  },
   "size":"1000",
               "sort": [
              {"date": "desc"}
          ]
}

CodePudding user response:

Your query is ill-formed, you need to combine your constraints using bool/filter/must queries

This will work:

{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "category": {
              "query": "الأنظمة",
              "operator": "and"
            }
          }
        }
      ],
      "filter": [
        {
          "range": {
            "date": {
              "gte": "1970-01-01",
              "lt": "2400-01-01"
            }
          }
        }
      ]
    }
  },
  "size": "1000",
  "sort": [
    {
      "date": "desc"
    }
  ]
}
  • Related