0

I'm doing elasticsearch in node js. Through 'client.search', I can get data from elasticsearch, but I just want to get '_source' field. How can I do this??

Through javascript 'map' function, I can get only _source data. However, I want to know what is the body option in 'client.search' to get only source data.

This is my code that is used map function.

    index: 'bank',
    body:{
      query:{
        "bool":{
          "must":{"match":{"state":"AL"}}
        }
      }
    }
  }, function getMore(err,data){
    if(err)
    {
      console.log(err);
      return;
    }
    var source = data.hits.hits.map(function(obj){
      return obj._source;
    });
    console.log(source);
    res.end(source);
  });

1 Answer 1

1

With client.search() there's no other way.

However, when retrieving a single document, you can use client.getSource() instead of client.get().

Sign up to request clarification or add additional context in comments.

1 Comment

Hi Val! Thanks for answering!! I see..!!

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.