@@ -94,6 +94,46 @@ parameter named `source`.
94
94
Both HTTP GET and HTTP POST can be used to execute search with body. Since not
95
95
all clients support GET with body, POST is allowed as well.
96
96
97
+ [float]
98
+ === Fast check for any matching docs
99
+
100
+ In case we only want to know if there are any documents matching a
101
+ specific query, we can set the `size` to `0` to indicate that we are not
102
+ interested in the search results. Also we can set `terminate_after` to `1`
103
+ to indicate that the query execution can be terminated whenever the first
104
+ matching document was found (per shard).
105
+
106
+ [source,js]
107
+ --------------------------------------------------
108
+ $ curl -XGET 'http://localhost:9200/_search?q=tag:wow&size=0&terminate_after=1'
109
+ --------------------------------------------------
110
+
111
+ The response will not contain any hits as the `size` was set to `0`. The
112
+ `hits.total` will be either equal to `0`, indicating that there were no
113
+ matching documents, or greater than `0` meaning that there were at least
114
+ as many documents matching the query when it was early terminated.
115
+ Also if the query was terminated early, the `terminated_early` flag will
116
+ be set to `true` in the response.
117
+
118
+ [source,js]
119
+ --------------------------------------------------
120
+ {
121
+ "took": 3,
122
+ "timed_out": false,
123
+ "terminated_early": true,
124
+ "_shards": {
125
+ "total": 1,
126
+ "successful": 1,
127
+ "failed": 0
128
+ },
129
+ "hits": {
130
+ "total": 1,
131
+ "max_score": 0,
132
+ "hits": []
133
+ }
134
+ }
135
+ --------------------------------------------------
136
+
97
137
98
138
include::request/query.asciidoc[]
99
139
0 commit comments