Is the query syntax of elasticsearch javascript api different from dsl?

I learned the DSL syntax, but the syntax of the client api seems to be different?

https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/search_examples.html

question 1

>     async function run () {
>       const { body } = await client.get({
>         index: 'abp_schedulerlogs_*', 
>         id: "-ds0CnIBhsM6auivt302",
>         body: {
>          bool:{                    <<< Can't the bool field be used here?   ResponseError: parsing_exception
>           filter: {                              
>             term: {
>               "JobInfoId": "08d7f0c3-c93d-4f01-888e-41a1f57671c5"
>     		},
>     	       term: {
>               "SourceType": "RootJob"
>     	      }
>            }
>          }
>         }
>       })
>       console.log(body.hits.hits)
>     }

question 2

> async function run () {
> 
>   const { body } = await client.search({
>     index: 'abp_schedulerlogs_*', 
>     size: 10,
>     body: {
>      query: {
>        term: {
>            "JobInfoId": "08d7f0c3-c93d-4f01-888e-41a1f57671c5" 
>          }
>       }
>      }
>   })
>   console.log(body.hits.hits)         >>>>  Why the output is [] ?
> }

index sample

> {
>   "_index": "abp_schedulerlogs-xxx",
>   "_type": "_doc",
>   "_id": "cxFj8nEB-eJj46oJ53jS",
>   "_version": 1,
>   "_score": null,
>   "_source": {
>     "@timestamp": "2020-05-08T03:46:05.803Z",
>     "Id": "394a5528-d867-46c9-aa22-71f0d94eb421",
>     "@version": "1",
>     "SourceType": "RootJob",
>     "WorkNode": null,
>     "Category": 3,
>     "CreateTime": "2020-05-08T03:46:01.7422326Z",
>     "StackTrace": null,
>     "JobInfoId": "08d7f164-fc6e-4808-86f3-83d4e6f5110c",
>     "Message": "xxxx."
>   }
> }

question 3

I want to get the content of a specific time range

> async function run () {
> 
>   const { body } = await client.search({
>     index: 'abp_schedulerlogs_*',
>     size: 10,
>     body: {
>      query: {
>        match: {
>            "JobInfoId": "08d7f0c3-c93d-4f01-888e-41a1f57671c5"
>       },
>        range: {
>           "CreateTime": {"gte":"2020.01.01"}   
>       }
>      }
>     }
>   })
>   console.log(body.hits.hits)
> }

result: ResponseError: parsing_exception

I also encountered problems using mock

question 4

> mock.add({
>   method: 'POST',
>   path: '/abp_schedulerlogs_*/_search',
>   body: { query: { match: { "JobInfoId" : "08d7f0c3-c93d-4f01-888e-41a1f57671c5" } } }
> }, () => {
>   return {
>     hits: {
>       total: { value: 9, relation: 'eq' },
>       hits: []
>     }
>   }
> })

I did not understand the meaning of the result prompt

> { ResponseError: Response Error
>     at Class.response.on (/root/apm/node_modules/@elastic/elasticsearch/lib/Transport.js:296:25)
>     at emitNone (events.js:106:13)
>     at Class.emit (events.js:208:7)
>     at endReadableNT (/root/apm/node_modules/readable-stream/lib/_stream_readable.js:1010:12)
>     at _combinedTickCallback (internal/process/next_tick.js:139:11)
>     at process._tickCallback (internal/process/next_tick.js:181:9)
>   name: 'ResponseError',
>   meta: 
>    { body: { error: 'Mock not found' },
>      statusCode: 404,
>      headers: 
>       { 'content-type': 'application/json;utf=8',
>         date: '2020-05-15T03:41:28.579Z',
>         connection: 'keep-alive',
>         'content-length': 26 },
>      warnings: null,
>      meta: 
>       { context: null,
>         request: [Object],
>         name: 'elasticsearch-js',
>         connection: [Object],
>         attempts: 0,
>         aborted: false } } } { body: { error: 'Mock not found' },
>   statusCode: 404,
>   headers: 
>    { 'content-type': 'application/json;utf=8',
>      date: '2020-05-15T03:41:28.579Z',
>      connection: 'keep-alive',
>      'content-length': 26 },
>   warnings: null,
>   meta: 
>    { context: null,
>      request: { params: [Object], options: [Object], id: 1 },
>      name: 'elasticsearch-js',
>      connection: { url: 'http://192.168.10.139:9200/',
>         id: 'http://192.168.10.139:9200/',
>         headers: {},
>         deadCount: 0,
>         resurrectTimeout: 0,
>         _openRequests: 0,
>         status: 'alive',
>         roles: [Object] },
>      attempts: 0,
>      aborted: false } }

Hope someone can help me and point out the problem, thank.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.