JosepB
JosepB

Reputation: 2315

node.js elasticsearch API query search request sending a POST method instead of GET

I'm using the elasticsearch API for node.js to make the following query to aws elasticsearch.

The elasticsearch documentation says that the request body search uses the GET method.

I'm using wireshark to look at the request send by my application with the body search method and I see that the method used is a POST.

enter image description here

Why is sending a POST? I want to allow only GET request to my domain.

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);
    });

Upvotes: 0

Views: 1218

Answers (1)

IftekharDani
IftekharDani

Reputation: 3729

As I go through elasticsearch module and found that in search using POST.

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

Link : filePath

Upvotes: 1

Related Questions