sudo-suhas / elastic-builder

A Node.js implementation of the elasticsearch Query DSL :construction_worker:
https://elastic-builder.js.org
MIT License
508 stars 75 forks source link

termsQuery throws error when checking type of terms in REPL #85

Open austince opened 5 years ago

austince commented 5 years ago

node version: v8.11.3 esb version: 2.2.2

When using the termsQuery it incorrectly checks the terms type.

In the REPL:

esb.termsQuery('user', ['kimchy', 'elasticsearch'])
[ 'kimchy', 'elasticsearch' ] is of the type object
TypeError: Argument must be an instance of Array
    at checkType (/home/austin/Workspace/node_modules/elastic-builder/lib/core/util.js:34:15)
    at TermsQuery.values (/home/austin/Workspace/node_modules/elastic-builder/lib/queries/term-level-queries/terms-query.js:135:13)
    at new TermsQuery (/home/austin/Workspace/node_modules/elastic-builder/lib/queries/term-level-queries/terms-query.js:75:46)
    at Object.termsQuery (/home/austin/Workspace/node_modules/elastic-builder/lib/core/util.js:52:16)
sudo-suhas commented 5 years ago

@austince Thanks for reporting this. I have verified that this is an issue which only affects the REPL. The module works correctly when you require it inside node REPL:

elastic-builder on master [!] is 📦 v0.0.0-development
➜ node
> const esb = require('.')
undefined
> esb.termsQuery('user', ['kimchy', 'elasticsearch'])
TermsQuery {
  queryType: 'terms',
  _body: { terms: {} },
  _queryOpts: {},
  _isTermsLookup: false,
  _termsLookupOpts: {},
  _values: [ 'kimchy', 'elasticsearch' ],
  _field: 'user' }
>

I will check and correct this soon.

austince commented 5 years ago

Thanks @sudo-suhas! Yes, just using the node REPL is not a huge problem.