刷新Elasticsearch索引/实时搜索

时间:2012-07-21 15:17:55

标签: real-time elasticsearch

我正在为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

1 个答案:

答案 0 :(得分:5)

问题在于_refresh命令。

您无法刷新类型,只能刷新索引。我将刷新命令更改为:

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

现在已经修好了!

相关问题