Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow index filtering in field capabilities API #57276

Merged
merged 13 commits into from
Jun 17, 2020

Conversation

jimczi
Copy link
Contributor

@jimczi jimczi commented May 28, 2020

This change allows to use an index_filter in the field capabilities API. Indices are filtered from
the response if the provided query rewrites to match_none on every shard:

POST metrics-*/_field_caps?fields=*
{
    "index_filter": {
        "bool": {
            "must": [
                {
                    "range": {
                        "@timestamp": {
                            "gt": "2019"
                        }
                    }
                },
                ...
            ]
        }
    }
}

The filtering is done on a best-effort basis, it uses the can match phase to rewrite queries to match_none instead of fully executing the request. The first shard that can match the filter is used to create the field capabilities response for the entire index.

Closes #56195

This change allows to use an `index_filter` in the
field capabilities API. Indices are filtered from
the response if the provided query rewrites to `match_none`
on every shard:

````
GET metrics-*
{
  "index_filter": {
    "bool": {
      "must": [
        "range": {
          "@timestamp": {
            "gt": "2019"
          }
        }
      }
  }
}
````

The filtering is done on a best-effort basis, it uses the can match phase
to rewrite queries to `match_none` instead of fully executing the request.
The first shard that can match the filter is used to create the field
capabilities response for the entire index.

Closes elastic#56195
@jimczi jimczi added >feature :Search/Search Search-related issues that do not fall into other categories v8.0.0 v7.9.0 labels May 28, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (:Search/Search)

@elasticmachine elasticmachine added the Team:Search Meta label for search team label May 28, 2020
static Request fieldCaps(FieldCapabilitiesRequest fieldCapabilitiesRequest) {
Request request = new Request(HttpGet.METHOD_NAME, endpoint(fieldCapabilitiesRequest.indices(), "_field_caps"));
static Request fieldCaps(FieldCapabilitiesRequest fieldCapabilitiesRequest) throws IOException {
String methodName = fieldCapabilitiesRequest.indexFilter() != null ? HttpPut.METHOD_NAME : HttpGet.METHOD_NAME;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PUT? shouldn't it be a POST?

@@ -67,6 +67,7 @@ public TransportFieldCapabilitiesAction(TransportService transportService, Clust

@Override
protected void doExecute(Task task, FieldCapabilitiesRequest request, final ActionListener<FieldCapabilitiesResponse> listener) {
long nowInMillis = request.nowInMillis() == null ? System.currentTimeMillis() : request.nowInMillis();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: in what cases would the current timestamp already be set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

query rewrites to `match_none` on every shard.
+
--
[IMPORTANT]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we've duplicated this whole note, maybe we could just keep the one below?

@jimczi jimczi merged commit 90c9b95 into elastic:master Jun 17, 2020
@jimczi jimczi deleted the field_caps_index_filter branch June 17, 2020 20:53
jimczi added a commit that referenced this pull request Jun 18, 2020
This change allows to use an `index_filter` in the
field capabilities API. Indices are filtered from
the response if the provided query rewrites to `match_none`
on every shard:

````
GET metrics-*
{
  "index_filter": {
    "bool": {
      "must": [
        "range": {
          "@timestamp": {
            "gt": "2019"
          }
        }
      }
  }
}
````

The filtering is done on a best-effort basis, it uses the can match phase
to rewrite queries to `match_none` instead of fully executing the request.
The first shard that can match the filter is used to create the field
capabilities response for the entire index.

Closes #56195
jimczi added a commit to jimczi/elasticsearch that referenced this pull request Jun 18, 2020
This commit fixes the multi cluster yaml tests by restoring
the number of shards to 1 for the single_doc_index (removed in elastic#57276).

Closes elastic#58345
russcam added a commit to elastic/elasticsearch-net that referenced this pull request Jul 27, 2020
This commit introduces overloads of field_caps API
that do not take a body, as a BWC change for body introduced in
elastic/elasticsearch#57276
russcam added a commit to elastic/elasticsearch-net that referenced this pull request Jul 27, 2020
This commit introduces overloads of field_caps API
that do not take a body, as a BWC change for body introduced in
elastic/elasticsearch#57276

(cherry picked from commit 1f02223)
russcam added a commit to elastic/elasticsearch-net that referenced this pull request Jul 28, 2020
russcam added a commit to elastic/elasticsearch-net that referenced this pull request Jul 31, 2020
github-actions bot pushed a commit to elastic/elasticsearch-net that referenced this pull request Jul 31, 2020
github-actions bot pushed a commit to elastic/elasticsearch-net that referenced this pull request Jul 31, 2020
russcam added a commit to elastic/elasticsearch-net that referenced this pull request Jul 31, 2020
Relates: elastic/elasticsearch#57276

Co-authored-by: Russ Cam <russ.cam@elastic.co>
russcam added a commit to elastic/elasticsearch-net that referenced this pull request Jul 31, 2020
Relates: elastic/elasticsearch#57276

Co-authored-by: Russ Cam <russ.cam@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>feature release highlight :Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team v7.9.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a pre-filter query phase to field capabilities API
5 participants