ElasticSearch/npm: elasticdump: Unexpected token error during dumping of response data - node.js

While dumping the output of an elastic dump command, unexpected token error occurred as shown below. What is wrong here? Do i need to pass in a different data type here? Is it possible to take a look at the response being parsed?
##>elasticdump --input="https://<SERVER_IP>/elasticsearch/_search" --output="c:\edmp.log" --type=data
Wed, 24 May 2017 10:55:32 GMT | starting dump
undefined:1
<!DOCTYPE html>
^
SyntaxError: Unexpected token <
at Object.parse (native)
at Request._callback (C:\Users\user\AppData\Roaming\npm\node_modules\elast
icdump\lib\transports\elasticsearch.js:52:21)
at Request.self.callback (C:\Users\user\AppData\Roaming\npm\node_modules\e
lasticdump\node_modules\request\request.js:188:22)
at emitTwo (events.js:100:13)
at Request.emit (events.js:185:7)
at Request.<anonymous> (C:\Users\user\AppData\Roaming\npm\node_modules\ela
sticdump\node_modules\request\request.js:1171:10)
at emitOne (events.js:90:13)
at Request.emit (events.js:182:7)
at IncomingMessage.<anonymous> (C:\Users\user\AppData\Roaming\npm\node_mod
ules\elasticdump\node_modules\request\request.js:1091:12)
at IncomingMessage.g (events.js:273:16)

You need to remove the /_search in your --input specification and only specify the index name, like this
elasticdump \
--input="https://<SERVER_IP>/elasticsearch" \
--output="c:\edmp.log" \
--type=data
Now if you want to only retrieve data from the last 5 minutes you can also do it like this:
elasticdump \
--input="https://<SERVER_IP>/elasticsearch" \
--output="c:\edmp.log" \
--type=data \
--searchBody '{"query":{"range":{"datefield": {"gt": "now-5m"}}}}'

Related

Mongodb 5 node driver detailed schema validation error

Using mongodb 5 improved json schema validation errors (https://www.mongodb.com/developer/article/mongodb-5-0-schema-validation/), we should be able to have a detailed validation error when e.g inserting incorrect data in a document.
However, it does not seem to be working using latest mongodb node driver 4.2.
Here's the error I have :
MongoServerError: BSON field 'insert.documents.0' is the wrong type 'array', expected type 'object'
at MessageStream.messageHandler (/workspace/node_modules/mongodb/src/cmap/connection.ts:741:20)
at MessageStream.emit (events.js:400:28)
at MessageStream.emit (domain.js:470:12)
at processIncomingData (/workspace/node_modules/mongodb/src/cmap/message_stream.ts:167:12)
at MessageStream._write (/workspace/node_modules/mongodb/src/cmap/message_stream.ts:64:5)
at writeOrBuffer (internal/streams/writable.js:358:12)
at MessageStream.Writable.write (internal/streams/writable.js:303:10)
at Socket.ondata (internal/streams/readable.js:726:22)
at Socket.emit (events.js:400:28)
at Socket.emit (domain.js:470:12) {
ok: 0,
code: 14,
codeName: 'TypeMismatch'
Is there a way to have the detailed error message ?

how to pass a object inside the logger.log() file in winston#3.0.0 in nodejs

i have a http request in a variable queryData = qs.parse(requestBody);
when i try to parse through winston
logger.log("info","requestbody",+queryData);
even tried
logger.log("info","requestbody %s", queryData);
logger.log("info","requestbody",{queryData});
didn't worked
am getting error like:
{ TypeError: Cannot create property 'Symbol(level)' on string 'Registering Device typeac'
at DerivedLogger.log (/home/grl/www/node_modules/winston/lib/winston/logger.js:130:20)
at createOcfRes (/home/aol/www/iot-node-server.js:285:10)
at IncomingMessage.<anonymous> (/home/aol/www/iot-node-server.js:115:9)
at emitNone (events.js:86:13)
at IncomingMessage.emit (events.js:186:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9) level: 'error', timestamp: '19-07-2018 20:20:19' }

Error: An unexpected error has occurred. Firebase Functions

I have updated firebase-functions to version 1.0.2, firebase-tools to 3.18.4, firebase-admin to 5.12.0
I am uploading a function that generate thumbnails taken from https://github.com/firebase/functions-samples/tree/master/quickstarts/thumbnails
[debug] [2018-04-26T09:00:12.812Z] <<< HTTP RESPONSE 400
[debug] [2018-04-26T09:00:12.812Z] <<< HTTP RESPONSE BODY <?xml version='1.0' encoding='UTF-8'?><Error><Code>InvalidArgument</Code><Message>Invalid argument.</Message></Error>
[debug] [2018-04-26T09:00:12.813Z] TypeError: Cannot create property 'error' on string '<?xml version='1.0' encoding='UTF-8'?><Error><Code>InvalidArgument</Code><Message>Invalid argument.</Message></Error>'
at module.exports (C:\Users\NASA\AppData\Roaming\npm\node_modules\firebase-tools\lib\responseToError.js:11:16)
at Request._callback
(C:\Users\NASA\AppData\Roaming\npm\node_modules\firebase-tools\lib\api.js:47:25)
at Request.self.callback
(C:\Users\NASA\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\request\request.js:186:22)
at Request.emit (events.js:180:13)
at Request.emit (domain.js:421:20)
at Request.<anonymous>
(C:\Users\NASA\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\request\request.js:1163:10)
at Request.emit (events.js:180:13)
at Request.emit (domain.js:421:20)
at IncomingMessage.<anonymous>
(C:\Users\NASA\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\request\request.js:1085:12)
at Object.onceWrapper (events.js:272:13)
[error] Error: An unexpected error has occurred.
You said that:
You have updated firebase-functions to version 1.0.2
The code is cloned from the Cloud Function sample without any change
So most probably your problem comes form the fact that Cloud Functions V1.0.0 and above have changed, see the doc https://firebase.google.com/docs/functions/beta-v1-diff#storage
You should change from
exports.generateThumbnail = functions.storage.object().onFinalize((object) => {
to
exports.generateThumbnail = functions.storage.object().onFinalize((object, context) => {
and adapt accordingly the lines based on object, following the doc.

Create Task in Asana Node.js

Using the below in Node trying to create a task within Workspace. I have omitted the AccessToken & WorkspaceID numbers. Suspect I'm doing something really dumb :)
var asana = require('asana');
var client = asana.Client.create().useAccessToken('0/XXXXXXXX');
var newTask = { name: "Your Mission" };
client.tasks.createInWorkspace(1111111111, newTask).then(function(response) {
tasks = response.data;
console.log(tasks);
});
At runtime I get the following output...
Unhandled rejection Error: Invalid Request
at InvalidRequest.AsanaError (/Users/D/Asana_Crons/node_modules/asana/lib/errors/error.js:4:11)
at new InvalidRequest (/Users/D/Asana_Crons/node_modules/asana/lib/errors/invalid_request.js:5:14)
at Request._callback (/Users/D/Asana_Crons/node_modules/asana/lib/dispatcher.js:152:23)
at Request.self.callback (/Users/D/Asana_Crons/node_modules/request/request.js:186:22)
at emitTwo (events.js:125:13)
at Request.emit (events.js:213:7)
at Request.<anonymous> (/Users/D/Asana_Crons/node_modules/request/request.js:1163:10)
at emitOne (events.js:115:13)
at Request.emit (events.js:210:7)
at IncomingMessage.<anonymous> (/Users/D/Asana_Crons/node_modules/request/request.js:1085:12)
at Object.onceWrapper (events.js:314:30)
at emitNone (events.js:110:20)
at IncomingMessage.emit (events.js:207:7)
at endReadableNT (_stream_readable.js:1047:12)
at _combinedTickCallback (internal/process/next_tick.js:102:11)
at process._tickCallback (internal/process/next_tick.js:161:9)
The only issue I can see with your code is that the workspace id needs to be a string, not an integer. This is documented in the tasks section of /gen folder in the Asana Node client library.

Bad Request at respond node_modules/elasticsearch/src/lib/transport.js:264:15

I am very dummy on ElasticSearch and I have little experience with NodeJs. I have created few cruds using NodeJs + MongoDb. I have to change from MongoDb to ElasticSearch (this is mandatory). Please, I don't want to compare MOngoDb with ElasticSearch so don't try that.
I am following the example found here
https://blog.raananweber.com/2015/11/24/simple-autocomplete-with-elasticsearch-and-node-js/
I have started succesfully ElasticSearch. I can see:
nodejs express.js-elasticsearch-autocomplete-demo-master # curl --noproxy -XGET 'http://127.0.0.1:9200/?pretty'
{
"name" : "-em7X-s",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "cqJUaPcFREe4wX_YyYWoFg",
"version" : {
"number" : "5.2.1",
"build_hash" : "db0d481",
"build_date" : "2017-02-09T22:05:32.386Z",
"build_snapshot" : false,
"lucene_version" : "6.4.1"
},
"tagline" : "You Know, for Search"
}
However, when I try to start the sample above or access I get the error bellow respectvely:
/dev/samples/express.js-elasticsearch-autocomplete-demo-master $ npm start
> autocompleter#0.0.0 start /home/demetrio/dev/samples/express.js-elasticsearch-autocomplete-demo-master
> node ./bin/www
Elasticsearch INFO: 2017-02-16T20:00:48Z
Adding connection to http://localhost:9200/
Unhandled rejection Error: Bad Request
at respond (/home/demetrio/dev/samples/express.js-elasticsearch-autocomplete-demo-master/node_modules/elasticsearch/src/lib/transport.js:264:15)
at checkRespForFailure (/home/demetrio/dev/samples/express.js-elasticsearch-autocomplete-demo-master/node_modules/elasticsearch/src/lib/transport.js:223:7)
at HttpConnector.<anonymous> (/home/demetrio/dev/samples/express.js-elasticsearch-autocomplete-demo-master/node_modules/elasticsearch/src/lib/connectors/http.js:155:7)
at IncomingMessage.wrapper (/home/demetrio/dev/samples/express.js-elasticsearch-autocomplete-demo-master/node_modules/lodash/index.js:3095:19)
at emitNone (events.js:72:20)
at IncomingMessage.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:905:12)
at nextTickCallbackWith2Args (node.js:441:9)
at process._tickCallback (node.js:355:17)
Unhandled rejection Error: [illegal_argument_exception] request [/randomindex/_suggest] contains unrecognized parameter: [type]
at respond (/home/demetrio/dev/samples/express.js-elasticsearch-autocomplete-demo-master/node_modules/elasticsearch/src/lib/transport.js:264:15)
at checkRespForFailure (/home/demetrio/dev/samples/express.js-elasticsearch-autocomplete-demo-master/node_modules/elasticsearch/src/lib/transport.js:223:7)
at HttpConnector.<anonymous> (/home/demetrio/dev/samples/express.js-elasticsearch-autocomplete-demo-master/node_modules/elasticsearch/src/lib/connectors/http.js:155:7)
at IncomingMessage.wrapper (/home/demetrio/dev/samples/express.js-elasticsearch-autocomplete-demo-master/node_modules/lodash/index.js:3095:19)
at emitNone (events.js:72:20)
at IncomingMessage.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:905:12)
at nextTickCallbackWith2Args (node.js:441:9)
at process._tickCallback (node.js:355:17)
Unhandled rejection Error: [illegal_argument_exception] request [/randomindex/_suggest] contains unrecognized parameter: [type]
at respond (/home/demetrio/dev/samples/express.js-elasticsearch-autocomplete-demo-master/node_modules/elasticsearch/src/lib/transport.js:264:15)
at checkRespForFailure (/home/demetrio/dev/samples/express.js-elasticsearch-autocomplete-demo-master/node_modules/elasticsearch/src/lib/transport.js:223:7)
at HttpConnector.<anonymous> (/home/demetrio/dev/samples/express.js-elasticsearch-autocomplete-demo-master/node_modules/elasticsearch/src/lib/connectors/http.js:155:7)
at IncomingMessage.wrapper (/home/demetrio/dev/samples/express.js-elasticsearch-autocomplete-demo-master/node_modules/lodash/index.js:3095:19)
at emitNone (events.js:72:20)
at IncomingMessage.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:905:12)
at nextTickCallbackWith2Args (node.js:441:9)
at process._tickCallback (node.js:355:17)
I am very confused what to check. Any suggestion will be appreciated. My final target is to understand how to connect to ElasticSearch from NodeJs application

Resources