1

I want to autotest some things for elastic. One of them it's to: 1. GET all fields from mapping 2. Check that all fields are present 3. Check that fields with present _id in their names have type integer. But let's get started at least with returning mappings. I do it successfully in kibana console with

GET /persons/_mappings

But did not find any information about how to do it in requests: Currently, I have this request:

let client = await connectElastic();
        const response = await client.search({
            method: 'GET',
            index: 'persons',
            // perheps here must be some parameter?
        });

enter image description here

1 Answer 1

1

Using elasticsearch.js library elasticsearch.js:

first create client:

var elasticsearch = require('elasticsearch');
var client = new elasticsearch.Client({
  host: 'localhost:9200',
  log: 'trace'
});

You can use this api:

client.indices.getMapping({ index: 'persons'}, (err, res) => {
     if (!err) {
         console.log(res);
     }
});
Sign up to request clarification or add additional context in comments.

2 Comments

Hi Tarek. Thank you. That's exactly what I needed. I see I've read this elastic.co/guide/en/elasticsearch/client/javascript-api/current/… documentation in very "scratch the surface" manner. Need to read it thoroughly. By the way, you just missed a bit from my question. The client is already built, I don't know why you haven't seen it and proposed me to create the client :-)
You are very welcome Alexander. I know you created the client, I just wanted to include the require of the library, link to it, and creation of the client for anyone else who need the same solution :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.