有没有办法使用ElasticSearch script_fields的输出来更新索引中的另一个变量?Elasticsearch script_fields更新另一个字段?
我在ElasticSearch 1.x中有一个索引,它启用了时间戳,但没有存储。 (参见下面的映射)
这意味着该时间戳可以用于搜索使用类似script_fields被访问,或 -
GET twitter/_search
{
"script_fields": {
"script1": {
"script": "_fields['_timestamp']"
}
}
}
我需要提取该时间戳字段,并将其存储在索引中。写一个脚本来复制任何其他字段是很容易的,例如(我用的是更新API)
ctx._source.t1=ctx._source.message
但我怎么能使用该值从script_fields输出索引更新另一个领域?我希望字段'tcopy'获取每个文档的时间戳值。
此外,我试图用java来获取如下的值,但它返回null。
SearchResponse response = client.prepareSearch("twitter")
.setQuery(QueryBuilders.matchAllQuery())
.addScriptField("test", "doc['_timestamp'].value")
.execute().actionGet();
映射
{
"mappings": {
"tweet": {
"_timestamp": {
"enabled": true,
"doc_values" : true
},
"properties": {
"message": {
"type": "string"
},
"user": {
"type": "string"
},
"tcopy": {
"type": "long"
}
}
}
}
}
在脚本字段脚本中使用UpdateRequestBuilder,你不能用'_fields._timestamp'因为访问'_timestamp'它不会被存储,而是使用'doc._timestamp.value'代替。 – Val
但是,脚本更新将不允许您使用'doc._timestamp.value'。 – Val