0
我有以下幾點:如何查詢elasticsearch條目的TTL?
final settings = (ImmutableSettings.settingsBuilder()
.put('index._ttl.enabled', true)
.put('index.gateway.type', 'none')
.put('index.number_of_shards', 1)
.put('index.number_of_replicas', 0)
.put('index.store.type', 'memory')
.put('node.http.enabled', false)
.build())
node = (org.elasticsearch.node.NodeBuilder.nodeBuilder()
.clusterName(clusterName)
.local(true)
.settings(settings)
.node())
final Client client = node.client()
client.prepareIndex('index', 'type')
.setSource(jsonBuilder()
.startObject()
.field('_ttl', '111111')
.field('field', 'value')
.endObject())
.setRefresh(true)
.execute()
.actionGet()
以下:
SearchResponse searchResponse = client.prepareSearch('builds')
.setQuery(boolQuery()
.must(termQuery('_type', 'test')))
.execute()
.actionGet()
回報searchResponse.internalResponse.hits.hits[0].source
爲:
[0] = {[email protected]}"_ttl" -> "111111"
[1] = {[email protected]}"field" -> "value"
但下面的回報0L
:
client.prepareCount('index')
.setQuery(boolQuery()
.must(fieldQuery('_ttl', '111111'))
.must(termQuery('_type', 'type'))
.must(fieldQuery('field', 'value')))
.execute()
.actionGet()
.count
我該如何着手確保設置TTL?
你映射的樣子是什麼?你是否啓用了[_ttl字段](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-ttl-field.html)? – javanna
我_think_使用'.put('index._ttl.enabled',true)'啓用它。 –