Skip to content
Closed
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
5 changes: 5 additions & 0 deletions docs/changelog/120453.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 120453
summary: Support boolean strings for alias defination in CreateIndex API
area: Indices APIs
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@
is_write_index: false
test_clias:
is_write_index: true
test_dlias:
is_write_index: "true"

- do:
indices.get_alias:
Expand All @@ -107,6 +109,7 @@
- is_false: test_index.aliases.test_alias.is_write_index
- is_false: test_index.aliases.test_blias.is_write_index
- is_true: test_index.aliases.test_clias.is_write_index
- is_true: test_index.aliases.test_dlias.is_write_index

---
"Create index with invalid mappings":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ public class Alias implements Writeable, ToXContentFragment {
private static final ParseField SEARCH_ROUTING = new ParseField("search_routing", "searchRouting", "search-routing");
private static final ParseField IS_WRITE_INDEX = new ParseField("is_write_index");
private static final ParseField IS_HIDDEN = new ParseField("is_hidden");
private static final Set<String> KNOWN_FIELDS = Set.of(
FILTER.getPreferredName(),
ROUTING.getPreferredName(),
INDEX_ROUTING.getPreferredName(),
SEARCH_ROUTING.getPreferredName(),
IS_WRITE_INDEX.getPreferredName(),
IS_HIDDEN.getPreferredName()
);

private String name;

Expand Down Expand Up @@ -144,8 +152,12 @@ public Alias filter(QueryBuilder filterBuilder) {
* Associates a routing value to the alias
*/
public Alias routing(String routing) {
this.indexRouting = routing;
this.searchRouting = routing;
if (this.indexRouting == null) {
this.indexRouting = routing;
}
if (this.searchRouting == null) {
this.searchRouting = routing;
}
return this;
}

Expand Down Expand Up @@ -234,31 +246,21 @@ public static Alias fromXContent(XContentParser parser) throws IOException {
if (token == XContentParser.Token.FIELD_NAME) {
currentFieldName = parser.currentName();
// check if there are any unknown fields
Set<String> knownFieldNames = Set.of(
FILTER.getPreferredName(),
ROUTING.getPreferredName(),
INDEX_ROUTING.getPreferredName(),
SEARCH_ROUTING.getPreferredName(),
IS_WRITE_INDEX.getPreferredName(),
IS_HIDDEN.getPreferredName()
);
if (knownFieldNames.contains(currentFieldName) == false) {
if (KNOWN_FIELDS.contains(currentFieldName) == false) {
throw new IllegalArgumentException("Unknown field [" + currentFieldName + "] in alias [" + alias.name + "]");
}
} else if (token == XContentParser.Token.START_OBJECT) {
if (FILTER.match(currentFieldName, parser.getDeprecationHandler())) {
Map<String, Object> filter = parser.mapOrdered();
alias.filter(filter);
alias.filter(parser.mapOrdered());
}
} else if (token == XContentParser.Token.VALUE_STRING) {
} else if (token.isValue()) {
if (ROUTING.match(currentFieldName, parser.getDeprecationHandler())) {
alias.routing(parser.text());
} else if (INDEX_ROUTING.match(currentFieldName, parser.getDeprecationHandler())) {
alias.indexRouting(parser.text());
} else if (SEARCH_ROUTING.match(currentFieldName, parser.getDeprecationHandler())) {
alias.searchRouting(parser.text());
}
} else if (token == XContentParser.Token.VALUE_BOOLEAN) {
if (IS_WRITE_INDEX.match(currentFieldName, parser.getDeprecationHandler())) {
alias.writeIndex(parser.booleanValue());
} else if (IS_HIDDEN.match(currentFieldName, parser.getDeprecationHandler())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
if ("filter".equals(currentFieldName)) {
filter = parser.mapOrdered();
}
} else {
throw new IllegalArgumentException("Unknown token [" + token + "]");
}
}
}
Expand Down