0

This is the mapping.

curl -XPUT 'localhost:9200/products/' -d '{
    "settings" : {
        "index" : {
            "number_of_shards" : 6, 
            "number_of_replicas" : 1 
        }
    },
    "mappings" : {
        "product" : {
          "_all":{ "enabled": true  },
          "properties":{
            "id" : { "type" : "string", "index" : "not_analyzed", "include_in_all": true },
            "description" : { "type" : "string" },
            "title" : { "type" : "string", "boost" : 2 },
      }
        }
    }
}'

I don't want to get the ads which have no description. but as you can see in mapping "description" have an index. So how do I use not query in description? please help me out.

I seen the doc of elasticsearch and I use this query.

**query => {
    filtered => {
        filter => {
            not => {
                filter => {
                    term  => {description  => ''}
                }
            }
        },
        query => {
            match => { _all => $q }
        }
    }
}**

But it's not working, I think because description have index right?

1
  • ES version: 2.4 Commented Oct 25, 2016 at 9:51

1 Answer 1

2

For 2.4 this would be the correct syntax and query approach:

{
  "query": {
    "bool": {
      "must": [
        {"match_all": {}}
      ],
      "filter": {
        "bool": {
          "must": [
            {
              "exists": {
                "field": "description"
              }
            },
            {
              "wildcard": {
                "description": "*"
              }
            }
          ]
        }
      }
    }
  }
}

Instead of filtered you have a bool with must as query and filter as filter. What's inside ofmustis what you have as query and what's inside offilteris what you have as filter. The approach you used withfiltered` is deprecated in ES 2.x.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.