node.js elasticsearch API查询搜索请求发送POST方法而不是GET

时间:2018-09-24 11:49:07

标签: node.js elasticsearch aws-elasticsearch

我正在使用用于node.js的elasticsearch API来对AWS Elasticsearch进行following查询。

elasticsearch documentation说请求正文搜索使用GET方法。

我正在使用Wirehark来查看应用程序使用正文搜索方法发送的请求,并且我发现所使用的方法是POST。

enter image description here

为什么要发送POST?我只允许对我的域的GET请求。

elasticsearch.js

var elasticsearch = require('elasticsearch');

var AWS = require('aws-sdk');
AWS.config.update({ region: 'eu-central-1' });

var elasticClient = elasticsearch.Client({
  hosts: [ 'host' ],
  connectionClass: require('http-aws-es'),
  log: ['error', 'warning'],
    amazonES: {
        region: 'eu-central-1',
        accessKey: 'accessKey',
        secretKey: 'secretKey'
    }
 });

var indexName = "indexName";

var type = "records";
    function querySearch(data){
        console.log("[INFO]: Check data "+JSON.stringify(data));
        return elasticClient.search({
            index: indexName,
            type: type,
            body:  data
        });

    }

    exports.querySearch = querySearch; 

index.js

var elastic = require('./elasticsearch.js');
    elastic.querySearch({"query": {"bool": {"must": [{ "match": { "id": "value" } }]}}}).then(function (resp) {
        //If data doesn't exist in elasticsearch insert into Firehose
        if (resp.hits.hits.length == 0){
            console.log("[INFO]: No data");
        }else{
            console.log("[INFO]: Record already in Elasticsearch");
        }
    }, function (err) {
        console.trace("[ERROR]: "+err.message);
    });

1 个答案:

答案 0 :(得分:1)

当我浏览elasticsearch模块并使用searchPOST中发现它时。

pi.search = ca({
  params: {
    includeTypeName: {
      type: 'string',
      name: 'include_type_name'
    },
    ......
    method: 'POST'
});

链接:filePath