我在 flex 搜索中有以下文档:
{
"postDate": "2016-03-09T11:57:37+0530",
"message": "trying out Elasticsearch",
"user": "ankita",
"tags": [
"testing"
]
}
我正在尝试使用jestHttpClient通过以下代码更新它:
private static void updateDocument(JestClient client, String id) {
String script = "{\n" +
" \"script\" : \"ctx._source.tags += tag\",\n" +
" \"params\" : {\n" +
" \"tag\" : \"blue\"\n" +
" }\n" +
"}";
//String script ="{ \"script\" : \"ctx._source.newfield = \"something\"\"}";
try {
Update update=new Update.Builder(script).index("article").type("type").id(id).build();
client.execute(update);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
但这不是更新文档,不确定这里出了什么问题,
有没有一种方法可以在Elasticsearch中部分更新文档?
最佳答案
您需要确保elasticsearch.yml
配置文件中有enabled dynamic scripting。
由于您已经使用brew安装了ES,因此通常可以在/usr/local/Cellar/elasticsearch/2.2.0/config/elasticsearch.yml
上找到该配置文件。
只需将以下行添加到文件中并重新启动ES:
script.inline: true
之后,您的更新脚本应该可以工作了。
关于elasticsearch - 使用updateBuilder时不会发生Elasticsearch部分更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35884904/