get_or_create
在对 ES 执行多个请求时,我遇到了一些问题。Elasticsearch 在响应索引文档后似乎需要一些时间POST
,以至于刚刚GET
调用的 a没有返回任何结果。
此示例重现了该问题:
curl -XPOST 'http://localhost:9200/twitter/tweet/' -d '{
"user" : "kimchy",
"post_date" : "2009-11-15T14:12:12",
"message" : "trying out Elastic Search"
}' && \
curl -XGET 'http://localhost:9200/twitter/tweet/_search' -d '{
"query" : {
"term" : { "user" : "kimchy" }
}
}' && \
sleep 1 && \
curl -XGET 'http://localhost:9200/twitter/tweet/_search' -d '{
"query" : {
"term" : { "user" : "kimchy" }
}
}'
POST
进展顺利:
{
"ok": true,
"_index": "twitter",
"_type": "tweet",
"_id": "yaLwtgSuQcWg5lzgFpuqHQ",
"_version": 1
}
第一个GET
不匹配任何结果:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
短暂的停顿后,显示结果(第二个GET
):
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.30685282,
"hits": [{
"_index": "twitter",
"_type": "tweet",
"_id": "yaLwtgSuQcWg5lzgFpuqHQ",
"_score": 0.30685282,
"_source": {
"user": "kimchy",
"post_date": "2009-11-15T14:12:12",
"message": "trying out Elastic Search"
}
}]
}
}
这种行为正常吗?
即使响应速度较慢,是否有可能立即获得结果?
谢谢!