2013-08-28 19:24:34 -04:00
|
|
|
[[search-count]]
|
2019-07-19 14:35:36 -04:00
|
|
|
=== Count API
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2019-09-17 03:53:03 -04:00
|
|
|
Gets the number of matches for a search query.
|
|
|
|
|
|
|
|
[source,console]
|
|
|
|
--------------------------------------------------
|
2020-08-04 14:16:38 -04:00
|
|
|
GET /my-index-000001/_count?q=user:kimchy
|
2019-09-17 03:53:03 -04:00
|
|
|
--------------------------------------------------
|
2020-08-04 14:16:38 -04:00
|
|
|
// TEST[setup:my_index]
|
2019-09-17 03:53:03 -04:00
|
|
|
|
|
|
|
NOTE: The query being sent in the body must be nested in a `query` key, same as
|
2020-08-04 14:16:38 -04:00
|
|
|
the <<search-search,search API>> works.
|
2019-09-17 03:53:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
[[search-count-api-request]]
|
|
|
|
==== {api-request-title}
|
|
|
|
|
2020-06-30 15:52:34 -04:00
|
|
|
`GET /<target>/_count`
|
2019-09-17 03:53:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
[[search-count-api-desc]]
|
|
|
|
==== {api-description-title}
|
|
|
|
|
Deprecate REST access to System Indices (#63274) (Original #60945)
This PR adds deprecation warnings when accessing System Indices via the REST layer. At this time, these warnings are only enabled for Snapshot builds by default, to allow projects external to Elasticsearch additional time to adjust their access patterns.
Deprecation warnings will be triggered by all REST requests which access registered System Indices, except for purpose-specific APIs which access System Indices as an implementation detail a few specific APIs which will continue to allow access to system indices by default:
- `GET _cluster/health`
- `GET {index}/_recovery`
- `GET _cluster/allocation/explain`
- `GET _cluster/state`
- `POST _cluster/reroute`
- `GET {index}/_stats`
- `GET {index}/_segments`
- `GET {index}/_shard_stores`
- `GET _cat/[indices,aliases,health,recovery,shards,segments]`
Deprecation warnings for accessing system indices take the form:
```
this request accesses system indices: [.some_system_index], but in a future major version, direct access to system indices will be prevented by default
```
2020-10-06 15:41:40 -04:00
|
|
|
The count API allows you to execute a query and get the number of matches for
|
|
|
|
that query. The query can either
|
|
|
|
be provided using a simple query string as a parameter, or using the
|
2019-09-17 03:53:03 -04:00
|
|
|
<<query-dsl,Query DSL>> defined within the request body.
|
|
|
|
|
2020-06-30 15:52:34 -04:00
|
|
|
The count API supports <<multi-index,multi-target syntax>>. You can run a single
|
|
|
|
count API search across multiple data streams and indices.
|
2019-09-17 03:53:03 -04:00
|
|
|
|
Deprecate REST access to System Indices (#63274) (Original #60945)
This PR adds deprecation warnings when accessing System Indices via the REST layer. At this time, these warnings are only enabled for Snapshot builds by default, to allow projects external to Elasticsearch additional time to adjust their access patterns.
Deprecation warnings will be triggered by all REST requests which access registered System Indices, except for purpose-specific APIs which access System Indices as an implementation detail a few specific APIs which will continue to allow access to system indices by default:
- `GET _cluster/health`
- `GET {index}/_recovery`
- `GET _cluster/allocation/explain`
- `GET _cluster/state`
- `POST _cluster/reroute`
- `GET {index}/_stats`
- `GET {index}/_segments`
- `GET {index}/_shard_stores`
- `GET _cat/[indices,aliases,health,recovery,shards,segments]`
Deprecation warnings for accessing system indices take the form:
```
this request accesses system indices: [.some_system_index], but in a future major version, direct access to system indices will be prevented by default
```
2020-10-06 15:41:40 -04:00
|
|
|
The operation is broadcast across all shards. For each shard id group, a replica
|
|
|
|
is chosen and executed against it. This means that replicas increase the
|
2019-09-17 03:53:03 -04:00
|
|
|
scalability of count.
|
|
|
|
|
|
|
|
|
|
|
|
[[search-count-api-path-params]]
|
|
|
|
==== {api-path-parms-title}
|
|
|
|
|
2020-06-30 15:52:34 -04:00
|
|
|
`<target>`::
|
2019-09-17 03:53:03 -04:00
|
|
|
|
2020-06-30 15:52:34 -04:00
|
|
|
(Optional, string)
|
2020-06-30 15:55:37 -04:00
|
|
|
Comma-separated list of data streams, indices, and index aliases to search.
|
|
|
|
Wildcard (`*`) expressions are supported.
|
2020-06-30 15:52:34 -04:00
|
|
|
+
|
|
|
|
To search all data streams and indices in a cluster, omit this parameter or use
|
|
|
|
`_all` or `*`.
|
2019-09-17 03:53:03 -04:00
|
|
|
|
|
|
|
[[search-count-api-query-params]]
|
|
|
|
==== {api-query-parms-title}
|
|
|
|
|
2020-06-01 19:42:53 -04:00
|
|
|
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=allow-no-indices]
|
2020-02-24 05:57:32 -05:00
|
|
|
+
|
|
|
|
Defaults to `true`.
|
2019-09-17 03:53:03 -04:00
|
|
|
|
2020-06-01 19:42:53 -04:00
|
|
|
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=analyzer]
|
2019-09-17 03:53:03 -04:00
|
|
|
|
2020-06-01 19:42:53 -04:00
|
|
|
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=analyze_wildcard]
|
2019-09-17 03:53:03 -04:00
|
|
|
|
2020-06-01 19:42:53 -04:00
|
|
|
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=default_operator]
|
2019-09-17 03:53:03 -04:00
|
|
|
|
2020-06-01 19:42:53 -04:00
|
|
|
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=df]
|
2019-09-17 03:53:03 -04:00
|
|
|
|
2020-06-01 19:42:53 -04:00
|
|
|
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=expand-wildcards]
|
2019-09-17 03:53:03 -04:00
|
|
|
+
|
|
|
|
Defaults to `open`.
|
|
|
|
|
2020-06-01 19:42:53 -04:00
|
|
|
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=ignore_throttled]
|
2019-09-17 03:53:03 -04:00
|
|
|
|
2020-06-01 19:42:53 -04:00
|
|
|
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=index-ignore-unavailable]
|
2019-09-17 03:53:03 -04:00
|
|
|
|
2020-06-01 19:42:53 -04:00
|
|
|
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=lenient]
|
2019-09-17 03:53:03 -04:00
|
|
|
|
|
|
|
`min_score`::
|
|
|
|
(Optional, float)
|
Deprecate REST access to System Indices (#63274) (Original #60945)
This PR adds deprecation warnings when accessing System Indices via the REST layer. At this time, these warnings are only enabled for Snapshot builds by default, to allow projects external to Elasticsearch additional time to adjust their access patterns.
Deprecation warnings will be triggered by all REST requests which access registered System Indices, except for purpose-specific APIs which access System Indices as an implementation detail a few specific APIs which will continue to allow access to system indices by default:
- `GET _cluster/health`
- `GET {index}/_recovery`
- `GET _cluster/allocation/explain`
- `GET _cluster/state`
- `POST _cluster/reroute`
- `GET {index}/_stats`
- `GET {index}/_segments`
- `GET {index}/_shard_stores`
- `GET _cat/[indices,aliases,health,recovery,shards,segments]`
Deprecation warnings for accessing system indices take the form:
```
this request accesses system indices: [.some_system_index], but in a future major version, direct access to system indices will be prevented by default
```
2020-10-06 15:41:40 -04:00
|
|
|
Sets the minimum `_score` value that documents must have to be included in the
|
2019-09-17 03:53:03 -04:00
|
|
|
result.
|
|
|
|
|
2020-06-01 19:42:53 -04:00
|
|
|
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=preference]
|
2019-09-17 03:53:03 -04:00
|
|
|
|
2020-06-01 19:42:53 -04:00
|
|
|
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=search-q]
|
2019-09-17 03:53:03 -04:00
|
|
|
|
2020-06-01 19:42:53 -04:00
|
|
|
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=routing]
|
2019-09-17 03:53:03 -04:00
|
|
|
|
2020-06-01 19:42:53 -04:00
|
|
|
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=terminate_after]
|
2019-09-17 03:53:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
[[search-count-request-body]]
|
|
|
|
==== {api-request-body-title}
|
|
|
|
|
2020-06-01 19:42:53 -04:00
|
|
|
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=query]
|
2019-09-17 03:53:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
[[search-count-api-example]]
|
|
|
|
==== {api-examples-title}
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2019-09-06 16:09:09 -04:00
|
|
|
[source,console]
|
2013-08-28 19:24:34 -04:00
|
|
|
--------------------------------------------------
|
2020-08-04 14:16:38 -04:00
|
|
|
PUT /my-index-000001/_doc/1?refresh
|
2016-05-18 07:36:19 -04:00
|
|
|
{
|
2020-08-04 14:16:38 -04:00
|
|
|
"user.id": "kimchy"
|
2016-05-18 07:36:19 -04:00
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2020-08-04 14:16:38 -04:00
|
|
|
GET /my-index-000001/_count?q=user:kimchy
|
2016-05-18 07:36:19 -04:00
|
|
|
|
2020-08-04 14:16:38 -04:00
|
|
|
GET /my-index-000001/_count
|
2013-08-28 19:24:34 -04:00
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"query" : {
|
2020-08-04 14:16:38 -04:00
|
|
|
"term" : { "user.id" : "kimchy" }
|
2020-07-21 15:49:58 -04:00
|
|
|
}
|
2016-05-18 07:36:19 -04:00
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
|
2020-08-04 14:16:38 -04:00
|
|
|
Both examples above do the same: count the number of documents in
|
|
|
|
`my-index-000001` with a `user.id` of `kimchy`. The API returns the following response:
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2019-09-06 09:22:08 -04:00
|
|
|
[source,console-result]
|
2013-08-28 19:24:34 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"count": 1,
|
|
|
|
"_shards": {
|
|
|
|
"total": 1,
|
|
|
|
"successful": 1,
|
|
|
|
"skipped": 0,
|
|
|
|
"failed": 0
|
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
The query is optional, and when not provided, it will use `match_all` to
|
|
|
|
count all the docs.
|