我正在为 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 文档不是很有帮助。