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

Get Mapping API to honour allow_no_indices and ignore_unavailable #31507

Merged
merged 2 commits into from
Jun 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,24 @@
indices.get_mapping:
index: test_index

---
"Index missing, ignore_unavailable=true":
- skip:
version: " - 6.99.99"
reason: ignore_unavailable was ignored in previous versions
- do:
indices.get_mapping:
index: test_index
ignore_unavailable: true

- match: { '': {} }

---
"Index missing, ignore_unavailable=true, allow_no_indices=false":
- do:
catch: missing
indices.get_mapping:
index: test_index
ignore_unavailable: true
allow_no_indices: false

Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,26 @@ setup:

---
"Get test-* with wildcard_expansion=none":
- skip:
version: " - 6.99.99"
reason: allow_no_indices (defaults to true) was ignored in previous versions
- do:
catch: missing
indices.get_mapping:
index: test-x*
expand_wildcards: none

- match: { '': {} }
---
"Get test-* with wildcard_expansion=none allow_no_indices=false":
- skip:
version: " - 6.99.99"
reason: allow_no_indices was ignored in previous versions
- do:
catch: missing
indices.get_mapping:
index: test-x*
expand_wildcards: none
allow_no_indices: false
---
"Get test-* with wildcard_expansion=open,closed":

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.elasticsearch.common.util.set.Sets;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.indices.TypeMissingException;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.BytesRestResponse;
Expand Down Expand Up @@ -89,14 +88,9 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
@Override
public RestResponse buildResponse(final GetMappingsResponse response, final XContentBuilder builder) throws Exception {
final ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappingsByIndex = response.getMappings();
if (mappingsByIndex.isEmpty() && (indices.length != 0 || types.length != 0)) {
if (indices.length != 0 && types.length == 0) {
builder.close();
return new BytesRestResponse(channel, new IndexNotFoundException(String.join(",", indices)));
} else {
builder.close();
return new BytesRestResponse(channel, new TypeMissingException("_all", String.join(",", types)));
}
if (mappingsByIndex.isEmpty() && types.length != 0) {
builder.close();
return new BytesRestResponse(channel, new TypeMissingException("_all", String.join(",", types)));
}

final Set<String> typeNames = new HashSet<>();
Expand Down