elastic-builder icon indicating copy to clipboard operation
elastic-builder copied to clipboard

termsQuery throws error when checking type of terms in REPL

Open austince opened this issue 6 years ago • 2 comments

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)

austince avatar Mar 05 '19 20:03 austince

@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.

sudo-suhas avatar Mar 06 '19 05:03 sudo-suhas

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

austince avatar Mar 06 '19 15:03 austince