2012-07-21 135 views
2

我正在为ElasticSearch数据源编写单元测试,但是,我得到了混合结果。问题是,match_all查询没有找到我提交的记录,但是,当我使用CURL以单元测试的相同顺序手动运行命令时,我能够找到记录。刷新弹性搜索索引/实时搜索

我相信可能索引没有刷新,所以我在提交记录后开始运行“refresh”api命令,但是这也没有奏效。这里是我的命令列表 - 如果有人对如何确保这些命令即使连续立即运行有任何建议,也会有所帮助。

命令的单元测试运行:

curl -XGET 'http://localhost:9200/test_index/_mapping' 

curl -XDELETE 'http://localhost:9200/test_index/test_models' 

curl -XPOST 'http://localhost:9200/test_index/test_models/_refresh' -d '{}' 

curl -XPUT 'http://localhost:9200/test_index/test_models/_mapping' -d '{"test_models":{"properties":{"TestModel":{"properties":{"id":{"type":"string","index":"not_analyzed"},"string":{"type":"string"},"created":{"type":"date","format":"yyyy-MM-dd HH:mm:ss"},"modified":{"type":"date","format":"yyyy-MM-dd HH:mm:ss"}},"type":"object"}}}}' 

curl -XPOST 'http://localhost:9200/test_index/test_models/_bulk' -d '{"index":{"_index":"test_index","_type":"test_models","_id":"test-model"}} 
{"TestModel":{"id":"test-model","string":"Analyzed for terms","created":"2012-01-01 00:00:00","modified":"2012-02-01 00:00:00"}} 
' 

curl -XPOST 'http://localhost:9200/test_index/test_models/_refresh' -d '{}' 

curl -XGET 'http://localhost:9200/test_index/_mapping' 

curl -XGET 'http://localhost:9200/test_index/test_models/_search' -d '{"query":{"match_all":{}},"size":10}' 

这个问题也被张贴到(超级真棒)ElasticSearch邮件列表:

https://groups.google.com/forum/?fromgroups#!topic/elasticsearch/Nxv0XpLDY4k

-DK

回答

5

问题使用_refresh命令。

你不能刷新一个类型,只有一个索引。我将刷新命令更改为:

curl -XPOST 'http://localhost:9200/test_index/_refresh' 

现在已修复!