0

I am using Elasticsearch V7.

I want to fetch only the source fields from Elasticsearch.

Request query:

GET /test/_search?filter_path=hits.hits._source
{
  "query": {
    "term": {
      "test": {
        "value": "123"
      }
    }
  }
}

Response:

{
  "hits" : {
    "hits" : [
      {
        "_source" : {
          "field1" : "value1",
          "field2" : "value2",
          "field3" : "value3",
        }
      }
    ]
  }
}

Expected Result:

{
  "hits" : {
    "hits" : [
      {
          "field1" : "value1",
          "field2" : "value2",
          "field3" : "value3",
      }, 
      {
          "field1" : "value1",
          "field2" : "value2",
          "field3" : "value3",
      }
    ]
  }
}

OR

    "hits" : [
      {
          "field1" : "value1",
          "field2" : "value2",
          "field3" : "value3",
      }, 
      {
          "field1" : "value1",
          "field2" : "value2",
          "field3" : "value3",
      }
    ]

Is there a way to fetch the above expected result from Elasticsearch?

1 Answer 1

1

No, it's not possible. filter_path is as good as it gets when it comes to native response filtering.

Having said that, you can use jq -- the command line JSON processor -- to extract the _sources further:

curl -XGET "http://localhost:9200/test/_search?filter_path=hits.hits._source" \
     -H 'Content-Type: application/json' \
     -d'{ 
          "query": {   
              "match_all": {} 
          }
        }' \
    | jq '{hits: [.hits.hits[]._source]}'
Sign up to request clarification or add additional context in comments.

Comments

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.