Skip to content

Fields caps does not honour ignore_unavailable#116021

Merged
drempapis merged 16 commits intoelastic:mainfrom
drempapis:fields_caps_does_not_honour_ignore_unavailable
Nov 7, 2024
Merged

Fields caps does not honour ignore_unavailable#116021
drempapis merged 16 commits intoelastic:mainfrom
drempapis:fields_caps_does_not_honour_ignore_unavailable

Conversation

@drempapis
Copy link
Copy Markdown
Contributor

Querying an existing and closed index fails with cluster_block_exception when the _field_caps with ignore_unavailable=true is called.

The close State is not considered when filtering "unavailable," missing, or unacceptable resources, propagating closed indices to the method TransportFieldCapabilitiesAction::checkIndexBlocks, which raises an exception.

In this PR, state-related code was added to filter out closed indices.

Closes #107767

@drempapis drempapis added >bug Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch :Search Foundations/Search Catch all for Search Foundations v9.0.0 v8.17.0 labels Oct 31, 2024
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-search-foundations (Team:Search Foundations)

…ogic to exclude closed indices to the TransportFieldsCapabilitiesAction class to avoid business-logic conflicts with implementation for other Actions.
@drempapis
Copy link
Copy Markdown
Contributor Author

I updated the code after detecting test failures on ci. I moved the logic to exclude closed indices to the TransportFieldsCapabilitiesAction class to avoid business-logic conflicts with implementation for other Actions.

if (metadata != null && metadata.getState() == IndexMetadata.State.CLOSE) {
if (ignoreUnavailable) return false;
else throw new IndexClosedException(metadata.getIndex());
} else return true;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am a bit outdated on how indices resolution works these days, after recent refactoring. I was somehow not expecting that you need to explicitly handle closed indices, rather that provided indices and indices options, the method does what it needs to do, meaning not return closed indices. Can you double check that that option is no longer possible?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you, @javanna, for reviewing the pr. You are right. Further debugging the code, I found that for the incoming requests, the allowClosedIndices is set to true. Changing the default value at the FieldCapabilitiesRequest level, mitigates that issue.

…he ignoreUnavailable set in the URL request. Changing that value in the corresponding Request class will make it false.
@drempapis drempapis requested a review from javanna November 5, 2024 13:20
public final class FieldCapabilitiesRequest extends ActionRequest implements IndicesRequest.Replaceable, ToXContentObject {
public static final String NAME = "field_caps_request";
public static final IndicesOptions DEFAULT_INDICES_OPTIONS = IndicesOptions.strictExpandOpen();
public static final IndicesOptions DEFAULT_INDICES_OPTIONS = IndicesOptions.strictExpandOpenAndForbidClosed();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice! I believe this is ok. The doubt I have is just about the fact that we are changing index resolution for the field caps API, and that will affect existing usage. Yet if this is only to avoid errors when targeting closed indices, I think that's the right call, assuming there are no side effects. Are you able to get a green build?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you, @javanna, I'll proceed with that

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am not 100% sure I am following this. Why are we changing the default behaviour? Don't we want the change only when we get ignore_unavailable=true?
My reasoning here is: if we target a closed index an we have ignore_unavailable=false we want an error back, while if the request has ignore_unavailable=true we can safely skip closed indices.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you, @piergm, for the review. The allowClosedIndices is set to true in IndicesOptions.strictExpandOpen(), which affects the URL parameter ignore_unavailable behavior.

In the main branch, having a closed index for any value of ignore_unavailable, we get an exception of type.
cluster_block_exception. After changing the options in the field request, the API works as expected, returning an IndexClosedException for ignore_unavailable=false.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh I see, thank you for the clarification!

@drempapis
Copy link
Copy Markdown
Contributor Author

@elasticmachine update branch

@drempapis
Copy link
Copy Markdown
Contributor Author

@elasticmachine update branch

Copy link
Copy Markdown
Member

@piergm piergm left a comment

Choose a reason for hiding this comment

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

LGTM, just one small nit 😄

@cla-checker-service
Copy link
Copy Markdown

cla-checker-service bot commented Nov 7, 2024

💚 CLA has been signed

@drempapis
Copy link
Copy Markdown
Contributor Author

@elasticmachine run elasticsearch-ci/part-4

@drempapis
Copy link
Copy Markdown
Contributor Author

@elasticmachine test this please

@drempapis
Copy link
Copy Markdown
Contributor Author

@elasticmachine update branch

Copy link
Copy Markdown
Contributor

@javanna javanna left a comment

Choose a reason for hiding this comment

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

LGTM thanks @drempapis

@drempapis drempapis merged commit 3ae7921 into elastic:main Nov 7, 2024
drempapis added a commit to drempapis/elasticsearch that referenced this pull request Nov 7, 2024
The IndicesOption has been updated into the FieldCapabilitiesRequest to encapsulate the following logic.

If we target a closed index and ignore_unavailable=false, we get an IndexClosedException, otherwise
 if the request contains ignore_unavailable=true, we safely skip the closed index.
drempapis added a commit to drempapis/elasticsearch that referenced this pull request Nov 7, 2024
The IndicesOption has been updated into the FieldCapabilitiesRequest to encapsulate the following logic.

If we target a closed index and ignore_unavailable=false, we get an IndexClosedException, otherwise
 if the request contains ignore_unavailable=true, we safely skip the closed index.

(cherry picked from commit 3ae7921)
@drempapis
Copy link
Copy Markdown
Contributor Author

💚 All backports created successfully

Status Branch Result
8.x

Questions ?

Please refer to the Backport tool documentation

kderusso pushed a commit to kderusso/elasticsearch that referenced this pull request Nov 7, 2024
The IndicesOption has been updated into the FieldCapabilitiesRequest to encapsulate the following logic.

If we target a closed index and ignore_unavailable=false, we get an IndexClosedException, otherwise
 if the request contains ignore_unavailable=true, we safely skip the closed index.
elasticsearchmachine pushed a commit that referenced this pull request Nov 7, 2024
The IndicesOption has been updated into the FieldCapabilitiesRequest to encapsulate the following logic.

If we target a closed index and ignore_unavailable=false, we get an IndexClosedException, otherwise
 if the request contains ignore_unavailable=true, we safely skip the closed index.

(cherry picked from commit 3ae7921)
jozala pushed a commit that referenced this pull request Nov 13, 2024
The IndicesOption has been updated into the FieldCapabilitiesRequest to encapsulate the following logic.

If we target a closed index and ignore_unavailable=false, we get an IndexClosedException, otherwise
 if the request contains ignore_unavailable=true, we safely skip the closed index.
jughosta added a commit to elastic/kibana that referenced this pull request Nov 19, 2024
…#199717)

- Closes: #199413
- Related: #199654
- Related ES PR: elastic/elasticsearch#116021
- Related ES PR: elastic/elasticsearch#116656

## Summary

This PR unskips tests and updates the Kibana API to the updated ES
responses.


### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Nov 19, 2024
…elastic#199717)

- Closes: elastic#199413
- Related: elastic#199654
- Related ES PR: elastic/elasticsearch#116021
- Related ES PR: elastic/elasticsearch#116656

## Summary

This PR unskips tests and updates the Kibana API to the updated ES
responses.

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

(cherry picked from commit f61c043)
paulinashakirova pushed a commit to paulinashakirova/kibana that referenced this pull request Nov 26, 2024
…elastic#199717)

- Closes: elastic#199413
- Related: elastic#199654
- Related ES PR: elastic/elasticsearch#116021
- Related ES PR: elastic/elasticsearch#116656

## Summary

This PR unskips tests and updates the Kibana API to the updated ES
responses.


### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
alexey-ivanov-es pushed a commit to alexey-ivanov-es/elasticsearch that referenced this pull request Nov 28, 2024
The IndicesOption has been updated into the FieldCapabilitiesRequest to encapsulate the following logic.

If we target a closed index and ignore_unavailable=false, we get an IndexClosedException, otherwise
 if the request contains ignore_unavailable=true, we safely skip the closed index.
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Dec 12, 2024
…elastic#199717)

- Closes: elastic#199413
- Related: elastic#199654
- Related ES PR: elastic/elasticsearch#116021
- Related ES PR: elastic/elasticsearch#116656

## Summary

This PR unskips tests and updates the Kibana API to the updated ES
responses.


### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
@drempapis drempapis self-assigned this Dec 17, 2024
@drempapis drempapis deleted the fields_caps_does_not_honour_ignore_unavailable branch January 22, 2025 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>bug :Search Foundations/Search Catch all for Search Foundations Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch v8.17.0 v9.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_field_caps doesn't honour ignore_unavailable option with closed index

5 participants