0

I'm working on setting up Elasticsearch DSL for a django project.

When I use Elasticsearch DSL to set up the index and doc_type everything works. I use sense(chrome plugin) and cURL to double-check if the index and doc_type mapping is added, and the objects I want to store is added, and it is.

The problem arises when I use the Elasticsearch DSL api definitions to submit queries - no results are found.

def experimental_test():
        connections.create_connection(hosts=['localhost:9200'])

        tests_index = Index('tests_index')
        tests_index.settings(
            number_of_shards=1,
            number_of_replicas=0
        )
        tests_index.doc_type(Test)
        tests_index.delete(ignore=404)
        tests_index.create()

        Test.init()
        test = Test(title='Foo')
        test.save()

        s = Search()
        s = s.doc_type(Test)
        s = s.query('match', title='Foo')
        print s.to_dict()
        response = s.execute()

Here is what the debug says is sent to Elasticsearch (the actual query):

[INFO 2015-06-29 15:50:24,705 elasticsearch.trace] curl -XGET 'http://localhost:9200/_all/test/_search?pretty' -d '{"query": {"match": {"title": "Foo"}}}'

But no results are found.

If I copy this query into Sense or terminal with cURL, it finds it.

Anyone have else have this particular problem?

Thanks for any answers that might lead me to understand what the problem is, or what can be done differently.

PS: The API docs aren't very helpful.

stju
  • 11
  • 1
  • can you change the method to POST in Sense and see if you still get results in Sense ? I believe browsers usually do not pass a request body via GET so the result you are getting in Sense is probably the query match_all – keety Jun 29 '15 at 15:14
  • I still get the correct result – stju Jun 29 '15 at 15:23

0 Answers0