0

I have following simple snippet:

PUT /lib36
{
  "mappings": {
    "_source": {"enabled": false}, 
    "properties": {
      "name": {
        "type": "text"
      },
      "description":{
        "type": "text"
      }
      
    }
  }
}

PUT /lib36/_doc/1
{
  "name":"abc",
  "description":"xyz"
}


POST /lib36/_search
{
  "query": {
    "match": {
      "name": "abc"
    }
  }
}

With "_source": {"enabled": false}, the queried result doesn't include _source field.

I would to know how to write the query that the query result has the _source field ,but only contain name field, but not description field.

Thanks!

1 Answer 1

1

You can use the source filtering of elasticsearch, but for that first you need to have _source enabled in your mapping.

You need to have below key-value in your search query JSON. below search will exclude all other fields apart from name.

{
  "query": {
    "match": {
      "name": "abc"
    }
  },
  "_source": [
    "name"
  ],
}
Sign up to request clarification or add additional context in comments.

2 Comments

You should also state that the mapping needs to have "_source": {"enabled": true} instead of false (or remove the line entirely)
@Val, yes, i was gng to do that only :D

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.