尝试在ElasticSearch服务中为AWS中的域创建索引。 ElasticSearch版本为6.4。
最初,我收到406 (Not Acceptable)
错误作为响应。在进一步调查中,EalsticSearch 6.x版本的甜甜圈也需要显式设置headers选项。但是这样做,我得到400 (Bad Request)
作为回应。
知道我在搞什么吗?
我的代码:
var https = require('https'),
aws4 = require('aws4'),
schema = require('./info2.json'),
datelib = require('date-and-time');
var sendReq = function(requestData) {
return new Promise((resolve, reject) => {
https.request(requestData, function(res) {
if(res.statusCode==200) {
console.log(res);
resolve();
}
else {
console.error(res);
reject(res.statusCode);
}
}
).end(requestData.body || '');
});
};
var formReqData = function(host, method, path, data) {
return {
host: host,
method: method,
path: path,
body: data ? JSON.stringify(data) : '',
headers: {
'Content-Type':'application/json'
}
}
};
var index = <index-name>;
var endPoint = '<domain-endpoint>.es.amazonaws.com';
var date = new Date();
const year = date.getFullYear();
var delIndex = formReqData(endPoint, 'DELETE', `/${index}-${year}`);
var createIndex = formReqData(endPoint, 'PUT', `/${index}-${year}`, schema);
executeRequest(aws4.sign(deleteIndexRequestData)).then(executeRequest(aws4.sign(createIndexRequestData)));
我的json定义:
{
"settings" : {
"number_of_shards" : 1,
"number_of_replicas" : 2
},
"mappings" : {
"audit" : {
"properties" : {
"audit1" : { "type" : "text" }
}
}
}
}