我正在为django项目设置Elasticsearch DSL .
当我使用Elasticsearch DSL来设置索引和doc_type时,一切正常 . 我使用sense(chrome插件)和cURL来仔细检查是否添加了index和doc_type映射,并添加了我想要存储的对象,它是 .
当我使用Elasticsearch DSL api定义提交查询时出现问题 - 没有找到结果 .
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()
以下是调试说发送到Elasticsearch的内容(实际查询):
[INFO 2015-06-29 15:50:24,705 elasticsearch.trace] curl -XGET'http:// localhost:9200 / _all / test / _search?pretty'-d'{“query”:{“match”: {“title”:“Foo”}}}'
但没有找到结果 .
如果我使用cURL将此查询复制到Sense或终端,它会找到它 .
还有其他人有这个特殊问题吗?
感谢您的任何答案,这些答案可能会让我了解问题是什么,或者可以采取哪些不同的方式 .
PS:API文档不是很有帮助 .