# Match all in js sdk does not return values, while curl does

**URL:** <https://discuss.elastic.co/t/match-all-in-js-sdk-does-not-return-values-while-curl-does/268322>\
**Category:** Elasticsearch\
**Created:** [March 25, 2021, 10:49am UTC](https://discuss.elastic.co/t/match-all-in-js-sdk-does-not-return-values-while-curl-does/268322 "2021-03-25T10:49:03Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![yishain11](https://avatars.discourse-cdn.com/v4/letter/y/df705f/32.png) [@yishain11](https://discuss.elastic.co/u/yishain11)\
**Post date:** [March 25, 2021, 10:49am UTC](https://discuss.elastic.co/t/match-all-in-js-sdk-does-not-return-values-while-curl-does/268322/1 "2021-03-25T10:49:03Z")

</div>

Hi elastic wizards.  
I have strange issue with elasticsearch (7.11). I have an index called "test\_index", and when I query it using curl and "match\_all" it returns a value, but when I use the node js client, it does not.  
Here is the curl:

```auto
 curl https://some_url/test_index/_search?pretty -H 'Content-type: application/json' -d '{"size":100,"from":0,"sort":[{"time":"desc"}],"query":{"match_all":{}}}'

```

and here is the nodejs query:

```auto
{"index":"test_index","size":100,"body":{"sort":[{"time":"desc"}],"query":{"match_all":{}}},"from":0}

```

After creating the query obj in node, I just use  
`esClient.search(EntireObj)`.  
The nodejs syntax was taken from:  
[Search | Elasticsearch Node.js client [7.x] | Elastic](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/search_examples.html)

There are no errors, just empty hits array in the nodejs case.  
What is wrong in my nodejs syntax that causes the "match\_all" search to return nothing?

Thanks!

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 25, 2021, 11:25am UTC](https://discuss.elastic.co/t/match-all-in-js-sdk-does-not-return-values-while-curl-does/268322/2 "2021-03-25T11:25:14Z")

</div>

What does `console.log(body)` return?

---

<div class="post-metadata">

**Author:** ![yishain11](https://avatars.discourse-cdn.com/v4/letter/y/df705f/32.png) [@yishain11](https://discuss.elastic.co/u/yishain11)\
**Post date:** [March 25, 2021, 11:35am UTC](https://discuss.elastic.co/t/match-all-in-js-sdk-does-not-return-values-while-curl-does/268322/3 "2021-03-25T11:35:40Z")

</div>

`console.log(entireObj.body)`  
shows:  
`{ sort: [{ time: 'desc' }], query: { match_all: {} } }`

If you meant the search resutls body, its:

```auto
{
      took: 9,
      timed_out: false,
      _shards: { total: 5, successful: 5, skipped: 0, failed: 0 },
      hits: { total: { value: 0, relation: 'eq' }, max_score: null, hits: [] }
    }

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 25, 2021, 11:48am UTC](https://discuss.elastic.co/t/match-all-in-js-sdk-does-not-return-values-while-curl-does/268322/4 "2021-03-25T11:48:59Z")

</div>

Yes that's what I meant. Thanks.

Are you sure you are hitting the same node (`some_url `) with curl and the JS code?

What happens if you send instead the following?

```auto
{"index":"test_index"}

```

---

<div class="post-metadata">

**Author:** ![yishain11](https://avatars.discourse-cdn.com/v4/letter/y/df705f/32.png) [@yishain11](https://discuss.elastic.co/u/yishain11)\
**Post date:** [March 25, 2021, 12:16pm UTC](https://discuss.elastic.co/t/match-all-in-js-sdk-does-not-return-values-while-curl-does/268322/5 "2021-03-25T12:16:19Z")

</div>

Actually it's even weirder. It happens even without a complex query.  
Let me tell the full story:  
This is a part of a test suite. I create a new doc (creating on the fly a new index), and then I search for it with "match\_all" and with term query (this is where I use the nodejs client).  
I tried now to see the results of the creation and see if the doc was accualy inserted, and it seems that is not.  
Here is the call that creates the doc:

```auto
    const res = await axios.put(
      `${elasticUrl}/test_index/_doc/1`,
      logdata,
      config
    );

```

Where the logData is JSON and config are auth headers.

The result is:

```auto
{ _index: 'test_index',
_type: '_doc',
_id: '1',
_version: 1,
result: 'created',
_shards: { total: 2, successful: 1, failed: 0 },
_seq_no: 0,
_primary_term: 1 }

```

After this, I do an empty search:

```auto
const res2 = await axios.get(`${elasticUrl}/test_index/_search`);

```

and I get:

```auto
{ took: 0,
  timed_out: false,
  _shards: { total: 5, successful: 5, skipped: 0, failed: 0 },
  hits:
   { total: { value: 0, relation: 'eq' },
     max_score: null,
     hits: [] } }

```

So it seems there is an underline issue, event before it reaches the "match\_all" query.  
What is going on?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 25, 2021, 1:24pm UTC](https://discuss.elastic.co/t/match-all-in-js-sdk-does-not-return-values-while-curl-does/268322/6 "2021-03-25T13:24:05Z")

</div>

> [@yishain11](#):
>
> Let me tell the full story:

That's better.

> [@yishain11](#):
>
> This is a part of a test suite.

You probably did not refresh the index before searching.

---

<div class="post-metadata">

**Author:** ![yishain11](https://avatars.discourse-cdn.com/v4/letter/y/df705f/32.png) [@yishain11](https://discuss.elastic.co/u/yishain11)\
**Post date:** [March 25, 2021, 1:32pm UTC](https://discuss.elastic.co/t/match-all-in-js-sdk-does-not-return-values-while-curl-does/268322/7 "2021-03-25T13:32:21Z")

</div>

Thank you for all your help.  
I still don't know what is the cause, but adding a delay of a few ms before querying solved the issue, so it seems elastic wasn't done indexing the doc when I tried to query it.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 25, 2021, 3:47pm UTC](https://discuss.elastic.co/t/match-all-in-js-sdk-does-not-return-values-while-curl-does/268322/8 "2021-03-25T15:47:27Z")

</div>

Don't rely on adding a pause but instead call explicitly [the refresh API](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-refresh.html#refresh-api-desc).

> Use the refresh API to explicitly refresh one or more indices. If the request targets a data stream, it refreshes the stream’s backing indices. A _refresh_ makes all operations performed on an index since the last refresh available for search.

Or use the `refresh=wait_for` option to your last index operation.  
But for tests, forcing a refresh is ok.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 22, 2021, 3:47pm UTC](https://discuss.elastic.co/t/match-all-in-js-sdk-does-not-return-values-while-curl-does/268322/9 "2021-04-22T15:47:30Z")

</div>

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