Skip to content

A more newbie friendly example on the readme.md page #893

Closed
@mcapodici

Description

@mcapodici

🚀 Feature Proposal

A more newbie friendly example on the readme.md page

Motivation

As a new user, I found it hard to get the example working. When searching for a library to use the code not working first time is annoying and might make me try another library or just not bother and use HTTP.

The reason it didn't work is because it tries to do a POST request in a search query, returning a 400 response code. I suggest changing this to a GET request, and putting an example document in the index to begin with.

Example

Here is an example:

const { Client } = require('@elastic/elasticsearch')
const client = new Client({ node: 'http://localhost:9200' })

// promise API
async function main() {

    await client.index({
        index: 'example-index',
        body: { counter: 1 }
    })

    const result = await client.search({
        index: 'example-index',
        q: 'counter:1'
    });

    console.log(result.body.hits.hits[0]);

};

main();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions