0

我正在使用 node.js 的 elasticsearch API 对aws elasticsearch进行以下查询。

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

我正在使用 wireshark 来查看我的应用程序使用正文搜索方法发送的请求,我看到使用的方法是 POST。

在此处输入图像描述

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

弹性搜索.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);
    });
4

1 回答 1

1

当我浏览elasticsearch 模块并发现search使用POST.

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

链接:文件路径

于 2018-09-24T12:44:59.120 回答