刷新弹性搜索索引/实时搜索

Dav*_*ann 2 real-time elasticsearch

我正在为ElasticSearch数据源编写单元测试,但是,我的结果好坏参半.问题是match_all查询没有找到我提交的记录,但是,当我使用CURL以相同的顺序手动运行命令单元测试时,我能够找到记录.

我相信也许索引没有刷新,因此,我在提交记录后开始运行"刷新"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}'
Run Code Online (Sandbox Code Playgroud)

这个问题也被发布到(超级棒)ElasticSearch邮件列表中:

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

-DK

Dav*_*ann 5

问题在于_refresh命令.

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

curl -XPOST 'http://localhost:9200/test_index/_refresh'
Run Code Online (Sandbox Code Playgroud)

它现在已经修好了!