如何使用elasticsearch-js(或其他方式)更新基于查询的文档? [英] How to update a document based on query using elasticsearch-js (or other means)?

查看:1569
本文介绍了如何使用elasticsearch-js(或其他方式)更新基于查询的文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想执行逐个查询,特别是更新一个特定文档,其中包含Gary的字段名称。我正在使用最新版本的elasticsearch(2.3)我正在使用官方ES客户端的nodejs。提供替代方法(查找文档,更新文档中的特定字段)将作为正确的答案是可以接受的。

I want to perform a update-by-query, specifically update a specific document that where field name that contains Gary. I am using the latest version of elasticsearch (2.3) I am using the official ES client for nodejs. Providing an alternative means to do this (find a document, update a specific field in the document) would be acceptable as a correct answer.

推荐答案

尚未在JavaScript客户端中发布。这将在2.3 API版本的JavaScript客户端库中提供。现在,JS客户端只支持apiVersion:2.2

This has not yet been released in the JavaScript client. This will be available in the 2.3 API version of the Javascript client library. Right now, the JS client only supports up to apiVersion: 2.2

您可以使用任何HTTP客户端(Postman,curl,/ head /,Sense,...)要点击REST端点并执行您需要的。

You can use any HTTP client (Postman, curl, /head/, Sense, ...) in order to hit the REST endpoint and carry out what you need.

如果您需要通过Node.js执行此操作,可以使用 http 这样的模块:

If you do need to do this through Node.js, you can use the http module like this:

var http = require('http');

var options = {
  host: 'localhost',
  port: 9200,
  path: '/your_index/your_type/_update_by_query',
  method: 'POST'
};

var req = http.request(options, function(resp){
  resp.on('data', function(chunk){
    // check update response
  });
}).on("error", function(e){
  console.log("Got error: " + e.message);
});

var query = {
  "script": {
    "inline": "ctx._source.field = 'value2'"
  },
  "query": {
    "term": {
      "field": "value1"
    }
  }
};

// write data to request body
req.write(JSON.stringify(query));
req.write('\n');
req.end();

这篇关于如何使用elasticsearch-js(或其他方式)更新基于查询的文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆