# Is there any way to use client.search() in elastic clients(node.js) without index parameter

**URL:** <https://discuss.elastic.co/t/is-there-any-way-to-use-client-search-in-elastic-clients-node-js-without-index-parameter/193299>\
**Category:** Elasticsearch\
**Created:** [August 1, 2019, 10:31am UTC](https://discuss.elastic.co/t/is-there-any-way-to-use-client-search-in-elastic-clients-node-js-without-index-parameter/193299 "2019-08-01T10:31:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jin1129](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jin1129/32/37454_2.png) [@Jin1129](https://discuss.elastic.co/u/Jin1129)\
**Post date:** [August 1, 2019, 10:31am UTC](https://discuss.elastic.co/t/is-there-any-way-to-use-client-search-in-elastic-clients-node-js-without-index-parameter/193299/1 "2019-08-01T10:31:17Z")

</div>

I have an account that only accessible to an index.  
So index name had to be written in node.url for avoiding security exception  
but I got error code 400(bad Request) instead of security Exception,  
because of missing index name in const body.

Is there any way to get search result without providing index name in client.search?  
please refer my node.js codes as following

```auto
const { Client } = require('@elastic/elasticsearch');
const { URL } = require('url');

const client = new Client({
    node: {
        url: new URL('https://sample.example.com/myindex'), //without index name, I got a security exception 
        username: 'test',
        password: 'test',
    
    },
});

async function run() {

  // Let's search!
    const { body } = await client.search({
        // index: '', //It's already written in node.URL
        type: '_docs', 
        body: { //to get all data
           
        },
    });

    console.log('The body content : ' + body.hits.hits);
}

run().catch(console.log);

```

---

<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:** [August 29, 2019, 10:31am UTC](https://discuss.elastic.co/t/is-there-any-way-to-use-client-search-in-elastic-clients-node-js-without-index-parameter/193299/2 "2019-08-29T10:31:20Z")

</div>

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