Léo*_*Léo 10 elasticsearch pyes
我在get_or_create向ES 执行多个请求时遇到了一些问题.Elasticsearch在响应POST索引文档后似乎需要一些时间,以至于刚刚GET调用后没有返回任何结果.
此示例重现了此问题:
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" }
}
}'
Run Code Online (Sandbox Code Playgroud)
该POST得好:
{
"ok": true,
"_index": "twitter",
"_type": "tweet",
"_id": "yaLwtgSuQcWg5lzgFpuqHQ",
"_version": 1
}
Run Code Online (Sandbox Code Playgroud)
第一个GET与任何结果都不匹配:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
Run Code Online (Sandbox Code Playgroud)
短暂停顿后,显示结果(第二个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"
}
}]
}
}
Run Code Online (Sandbox Code Playgroud)
这种行为是正常的吗?
即使响应较慢,是否有可能立即获得结果?
谢谢!
是的,这是正常的,弹性搜索默认每秒更新一次索引.
如果您需要立即更新,请在插入文档时在URL中包含refresh = true
从文档:
刷新
要在操作发生后立即刷新索引,以便文档立即显示在搜索结果中,可以将refresh参数设置为true.将此选项设置为true只应在仔细考虑并验证它不会导致性能不佳的情况下完成,无论是从索引还是从搜索的角度来看.请注意,使用get API获取文档是完全实时的.
| 归档时间: |
|
| 查看次数: |
1716 次 |
| 最近记录: |