Missing field query like FilterBuilders.missingFilter()

Hi,

is it possible to create a query for not existing field like missingFilter.

I use bool query with should clause to boost matching queries.

Example:

   "bool" : {
        "should" : [ {
          "terms" : {
            "devices" : [ "samsung" ],
            "boost" : 5.0
          }
        }, {
          "terms" : {
            "devices" : [ "htc" ],
            "boost" : 10.0
          }
        }
        } ],
        "minimum_should_match" : "1"
      }

If "devices"-field does not exist in document, document should match
nevertheless.

Thanks.
Greg.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hey

a possibility is to add a filtered query - containing an not + exists
filter - to your should clauses from the bool query like this:

{
"filtered" : {
"query" : { "match_all" : {} },
"filter" : {
"not" : {
"exists" : { "field" : "devices" }
}
}
}
}

See here for more:

When doing it this way, check for the scores of the matching document to
make sure you get the desired results.

--Alex

On Thu, Mar 7, 2013 at 3:59 PM, Greg linuxzwerg@gmail.com wrote:

Hi,

is it possible to create a query for not existing field like missingFilter.

I use bool query with should clause to boost matching queries.

Example:

   "bool" : {
        "should" : [ {
          "terms" : {
            "devices" : [ "samsung" ],
            "boost" : 5.0
          }
        }, {
          "terms" : {
            "devices" : [ "htc" ],
            "boost" : 10.0
          }
        }
        } ],
        "minimum_should_match" : "1"
      }

If "devices"-field does not exist in document, document should match
nevertheless.

Thanks.
Greg.

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Thanks, I have not come up with this idea :slight_smile:

Greg.

On Friday, March 8, 2013 1:06:25 PM UTC+1, Alexander Reelsen wrote:

Hey

a possibility is to add a filtered query - containing an not + exists
filter - to your should clauses from the bool query like this:

{
"filtered" : {
"query" : { "match_all" : {} },
"filter" : {
"not" : {
"exists" : { "field" : "devices" }
}
}
}
}

See here for more:
Elasticsearch Platform — Find real-time answers at scale | Elastic
When doing it this way, check for the scores of the matching document to
make sure you get the desired results.

--Alex

On Thu, Mar 7, 2013 at 3:59 PM, Greg <linux...@gmail.com <javascript:>>wrote:

Hi,

is it possible to create a query for not existing field like
missingFilter.

I use bool query with should clause to boost matching queries.

Example:

   "bool" : {
        "should" : [ {
          "terms" : {
            "devices" : [ "samsung" ],
            "boost" : 5.0
          }
        }, {
          "terms" : {
            "devices" : [ "htc" ],
            "boost" : 10.0
          }
        }
        } ],
        "minimum_should_match" : "1"
      }

If "devices"-field does not exist in document, document should match
nevertheless.

Thanks.
Greg.

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearc...@googlegroups.com <javascript:>.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.