Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Filter with querystring in elasticsearch

I send this query and it works fine. It returns filtered data:

{
    "query": {
        "bool": {
            "filter": [
                {
                    "match": {
                        "lang": "en"
                    }
                }
            ]
        }
    },
    "size": 10,
    "from": 0,
    "sort": []
}

If I want to search with searchstring then it workst fine too:

{
    "query": {
        "query_string": {
            "query": "big size"
        }
    },
    "size": 10,
    "from": 0,
    "sort": []
}

But I can’t get data from elastic by filter and searchstring together:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

{
    "query": {
        "query_string": {
            "query": "big size"
        },
        "bool": {
            "filter": [
                {
                    "match": {
                        "lang": "en"
                    }
                }
            ]
        }
    },
    "size": 10,
    "from": 0,
    "sort": []
}

I receive next error:

Error 400.
{"error":{"root_cause":[{"type":"parsing_exception","reason":"[query_string] malformed query, expected [END_OBJECT] but found [FIELD_NAME]","line":1,"col":76}],"type":"parsing_exception","reason":"[query_string] malformed query, expected [END_OBJECT] but found [FIELD_NAME]","line":1,"col":76},"status":400}

>Solution :

Your query needs to be restructured as shown below.

Query:

{
  "query": {
    "bool": {
      "must": [
        {
          "query_string": {
            "query": "big size"
          }
        }
      ],
      "filter": [
        {
          "match": {
            "lang": "en"
          }
        }
      ]
    }
  },
  "size": 10,
  "from": 0,
  "sort": []
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading