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

标签 node.js elasticsearch aws-elasticsearch

我正在使用 node.js 的 elasticsearch API 来制作 following查询到 aws elasticsearch。

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

我正在使用 wireshark 来查看我的应用程序使用正文搜索方法发送的请求,我看到使用的方法是 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);
    });

最佳答案

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

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

关于node.js elasticsearch API查询搜索请求发送POST方法而不是GET,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52478744/

相关文章:

elasticsearch - AWS Elasticsearch:更多负载下的性能问题

elasticsearch - 为什么 Elasticsearch Cluster JVM 内存压力不断增加?

python - 使用 python elasticsearch 在 AWS Elasticsearch 上搜索失败返回 411

node.js - URL 中的尾部斜线是什么?

javascript - 如果已经存储了这样的唯一值,如何重新尝试插入数据库

Elasticsearch 聚合按每个桶的前一个结果过滤

elasticsearch 7嵌套聚合文本关键字错误

javascript - 找不到模块 npm 脚本的导入功能

node.js - 推送到 vercel 后无法连接到 websocket 服务器

elasticsearch - 在拆分操作上标记不同的行