作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我创建了一条河流,该河流每小时运行一次以从DB中获取数据(使用jdbc river插件)。
select * from orders
select * from orders where deviceid > '(Max Id in Elastic search)'
最佳答案
由于ES坚持将"_id"
值转换为字符串,因此似乎没有使用"_id"
字段直接执行此操作的方法。但是有一种解决方法。
首先,我用几个文档设置了一个简单的索引,如下所示:
PUT /test_index
{
"settings": {
"number_of_shards": 1
}
}
POST /test_index/_bulk
{"index":{"_index":"test_index","_type":"doc","_id":1}}
{"title":"first doc"}
{"index":{"_index":"test_index","_type":"doc","_id":2}}
{"title":"second doc"}
{"index":{"_index":"test_index","_type":"doc","_id":3}}
{"title":"third doc"}
"_id"
是字符串:
POST /test_index/_search?search_type=count
{
"aggs": {
"max_id": {
"max": {
"field": "_id"
}
}
}
}
...
{
"error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[bQS7TqO9SfKSPQZYVXQBag][test_index][0]: ClassCastException[org.elasticsearch.index.fielddata.plain.PagedBytesIndexFieldData cannot be cast to org.elasticsearch.index.fielddata.IndexNumericFieldData]}]",
"status": 500
}
"path"
field中的
"_id"
参数进行了一些修改。
DELETE /test_index
PUT /test_index
{
"settings": {
"number_of_shards": 1
},
"mappings": {
"doc": {
"_id": {
"path": "doc_id"
}
}
}
}
"doc_id"
路径为文档建立索引:
POST /test_index/_bulk
{"index":{"_index":"test_index","_type":"doc"}}
{"title":"first doc","doc_id":1}
{"index":{"_index":"test_index","_type":"doc"}}
{"title":"second doc","doc_id":2}
{"index":{"_index":"test_index","_type":"doc"}}
{"title":"third doc","doc_id":3}
"_id"
仍然是字符串,但是
"doc_id"
是整数:
POST /test_index/_search
...
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 1,
"hits": [
{
"_index": "test_index",
"_type": "doc",
"_id": "1",
"_score": 1,
"_source": {
"title": "first doc",
"doc_id": 1
}
},
{
"_index": "test_index",
"_type": "doc",
"_id": "2",
"_score": 1,
"_source": {
"title": "second doc",
"doc_id": 2
}
},
{
"_index": "test_index",
"_type": "doc",
"_id": "3",
"_score": 1,
"_source": {
"title": "third doc",
"doc_id": 3
}
}
]
}
}
POST /test_index/_search?search_type=count
{
"aggs": {
"max_id": {
"max": {
"field": "doc_id"
}
}
}
}
...
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 0,
"hits": []
},
"aggregations": {
"max_id": {
"value": 3
}
}
}
关于elasticsearch - 如何从 Elasticsearch 获取最大_id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28811744/
我是一名优秀的程序员,十分优秀!