3

The goal of this example code is to figure out how to create a query consisting out of multiple filters and queries.

The below example is not working as expected.

  1. I want to be able to execute my search only on document which contain a certain "key". That what I'm trying to reach with the ExistsFilter, but when enabling I don't get any results back.

Any pointers to clear up this question?

#!/usr/bin/python

import pyes
conn = pyes.ES('sandbox:9200')
conn.index('{"test":{"field1":"value1","field2":"value2"}}','2012.9.23','test')

filter = pyes.filters.BoolFilter()
filter.add_must(pyes.filters.LimitFilter(1))
filter.add_must(pyes.filters.ExistsFilter('test')) #uncommenting this line returns the documents

query = pyes.query.BoolQuery()
query.add_must(pyes.query.TextQuery('test.field1','value1'))
query.add_must(pyes.query.TextQuery('test.field2','value2'))

search = pyes.query.FilteredQuery(query, filter)

for reference in conn.search(query=search,indices=['2012.9.23']):
    print reference
jay_t
  • 3,593
  • 4
  • 22
  • 27

1 Answers1

0

I don't use pyes (neither python). But, what I can see here is that some informations seems to miss in the ExistsFilter if I compare to the ExistsFilter documentation :

{
    "constant_score" : {
        "filter" : {
            "exists" : { "field" : "user" }
        }
    }
}

Could it be your issue?

dadoonet
  • 14,109
  • 3
  • 42
  • 49