Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

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.

image

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

    });

1 Answer

0 votes
by (44.4k points)

You can simply do this:

pi.search = ca({

  params: {

    includeTypeName: {

      type: 'string',

      name: 'include_type_name'

    },

    ......

    method: 'POST'

});

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer
asked Jul 18, 2019 in AWS by yuvraj (19.1k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...