Python code works, Node.js not. Why? ES AWS
I am totally shocked why my code in node.js doesnt work and with python works like a charm? It is so weird for me :( Could someone take a look please and tell me what I am doing wrong?
Python code:
from elasticsearch import Elasticsearch
import json
esclient = Elasticsearch(['https://61699**.eu-central-1.aws.cloud.es.io/recipes/'],
http_auth=('d**', 'e.**'), scheme="https")
response = esclient.search(index="", body=json.dumps({"query": {"match": {'Title':'Easter Bunny Cupcakes'}}}))
print response
Node.js code:
const elasticsearch = require('elasticsearch');
const AWS = require('aws-sdk');
const client = elasticsearch.Client({
hosts: ''61699**.eu-central-1.aws.cloud.es.io/recipes/',
connectionClass: require('http-aws-es'),
amazonES: {
accessKey: 'd**',
secretKey: 'e.**',
},
awsConfig: new AWS.Config({region: 'eu-central-1'}),
});
client.index({
index: '',
type: '_doc',
body: {
query: {
match: {
Title: 'Easter Bunny Cupcakes',
},
},
},
}, function(err, data) {
console.log(err);
});
Send your creds over in awsConfig, amazonES is no longer used
If you're running this on Lambda, be sure to include the session token int he creds as well
Do you have any working code example? it's so frustrating that it doesnt work with node.js :(
Should work for you...
const elasticsearch = require('elasticsearch');
const AWS = require('aws-sdk');
const client = elasticsearch.Client({
hosts: ''61699**.eu-central-1.aws.cloud.es.io/recipes/',
connectionClass: require('http-aws-es'),
awsConfig: new AWS.Config({
region: 'eu-central-1',
credentials: new AWS.Credentials(
'd**', // Access Key
'e.**', // Secret
'***', // If running on Lambda: Session Token (process.env.AWS_SESSION_TOKEN)
)
}),
});
Thank you for help :) Unfortunetly I am getting a such error:
Trace: [security_exception] action [indices:data/read/search] requires authentication, with { header={ WWW-Authenticate={ 0="Bearer realm=\"security\"" & 1="Basic realm=\"security\" charset=\"UTF-8\"" } } } at C:\Users\falent\Desktop\node\a.js:30:12 at process._tickCallback (internal/process/next_tick.js:68:7)
Do you know what does it mean?