- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有没有一种方法可以使用ElasticSearch script_fields的输出来更新索引中的另一个变量?
我在ElasticSearch 1.x中有一个已启用时间戳但未存储的索引。 (有关映射,请参见下文)
这意味着可以通过搜索或使用script_fields(例如-
GET twitter/_search
{
"script_fields": {
"script1": {
"script": "_fields['_timestamp']"
}
}
}
ctx._source.t1=ctx._source.message
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"
}
}
}
}
}
最佳答案
您需要分两次运行:
twitter
索引中提取时间戳数据,您可以例如使用
elasticdump这样:
elasticdump \
--input=http://localhost:9200/twitter \
--output=$ \
--searchBody '{"script_fields": {"ts": {"script": "doc._timestamp.value"}}}' > twitter.json
twitter.json
的文件,其内容如下:
{"_index":"twitter","_type":"tweet","_id":"1","_score":1,"fields":{"ts":[1496806671021]}}
{"_index":"twitter","_type":"tweet","_id":"2","_score":1,"fields":{"ts":[1496807154630]}}
{"_index":"twitter","_type":"tweet","_id":"3","_score":1,"fields":{"ts":[1496807161591]}}
read.sh
的shell脚本
#!/bin/sh
while read LINE; do
INDEX=$(echo "${LINE}" | jq '._index' | sed "s/\"//g");
TYPE=$(echo "${LINE}" | jq '._type' | sed "s/\"//g");
ID=$(echo "${LINE}" | jq '._id' | sed "s/\"//g");
TS=$(echo "${LINE}" | jq '.fields.ts[0]');
curl -XPOST "http://localhost:9200/$INDEX/$TYPE/$ID/_update" -d "{\"doc\":{\"tcopy\":"$TS"}}"
done
./read.sh < twitter.json
tcopy
值的
_timestamp
字段。
关于elasticsearch - Elasticsearch script_fields更新另一个字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44400906/
我尝试使用“script_fields”为我的字段设置新值,但我看不到已在结果集中添加的“字段”,{ "query": { "my_type_x": xxx }, "script_
在使用自定义脚本时在Sort_context中。根据documentation我可以访问这些。 1)参数( map ,只读) 2)文档( map ,只读) 3) _score(双只读) 有没有办法,我
我已经创建了常规脚本来计算新的字段值。然后,我可以在我的查询中使用该脚本,使用 script_fields 参数计算新的字段值。这是一个例子: { "query": { "fi
我需要在无痛 script_fields 上迭代嵌套对象以进行查询,但符号 doc['nestedProperty.property'] 没有给我值,使用数组符号 doc['nestedPropert
我正在运行一个像这样的简单查询: { "query": { "term": { "statuses": "active" } }, "script_fields
我尝试使用 script_fields 从我的数据中检索数组值,但我收到了不一致的结果。 我的映射: curl -XPUT localhost:9200/test/user/_mapping -d '
我是一名优秀的程序员,十分优秀!