0
votes

I have a document that has nested fields. Example:

    "mappings": {
        "blogpost": {
          "properties": {
            "title": { "type": "text"  },
            "body":  { "type": "text"  },
            "comments": {
              "type": "nested", 
              "properties": {
                "name":    { "type": "text"  },
                "comment": { "type": "text"  },
                "age":     { "type": "short"   },
                "stars":   { "type": "short"   },
                "date":    { "type": "date"    }
              }
            }
          }
        }
  }
}

Can the query be modified so that the response only contains non-nested fields?

In this example, the response would only contain body and title.

Using _source you can exclude/include fields

GET /blogpost/_search
{
    "_source":{
        "excludes":["comments"]
    }
}

But you have to explicitly put the field names inside exclude, I'm searching for a way to exclude all nested fields without knowing their field name

1
Can you show the query you're sending now? - Val
yes, I've updated the post - Miguel Manjarrez

1 Answers

0
votes

You can achieve that but in a static way, which means you entered the field(s) name using excludes keyword, like:

GET your_index/_search
{
    "_source": {
        "excludes": "comments"  
    },
    "query": {
        "match_all" : {}
    }
}

excludes can take an array of strings; not just one string.