0

actually i want those record from my db where description is blank, below the mysql query for my result and what should be query in elasticsearch for same result ?

SELECT * FROM products WHERE description != '';

1 Answer 1

1

Elastic Search query looks like this

POST http://localhost:9200/<index>/<indextype>/_search
{
  "query": {
    "filtered": {
      "filter": {
        "term": {
          "description": ""
        }
      }
    }
  }
}

Still its not working, check your mapping should be like this.

PUT http://localhost:9200/<index>/<indextype>/_mapping
{
  "products": {
    "properties": {
      "description": {
        "type": "string",
        "index": "not_analyzed"
      }
    }
  }
}

If you want the result with description != '' then use below query.

Missing Filter in the Must-Not section of a Bool Filter. It will only return documents where the field exists, and if you set the "null_value" property to true, values that are explicitly not null.

{
  "query": {
    "filtered": {
      "filter": {
        "bool":{
          "must":{},
          "should":{},
          "must_not":{
             "missing":{
                "field":"description",
                "existence":true,
                "null_value":true
                }
            }
        }
      }
    }
  }
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks vinod, index must be "not_analyzed"? and if I want the result with description != '' then what should be query in elasticsearch?
i have updated my answer for you question. Please check.
checked Thans vinod

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.