Skip to content
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 @@ -28,7 +28,8 @@
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.ToXContent.Params;
import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
Expand All @@ -42,7 +43,7 @@
/**
* Represents an alias, to be associated with an index
*/
public class Alias implements Streamable, ToXContentObject {
public class Alias implements Streamable, ToXContentFragment {

private static final ParseField FILTER = new ParseField("filter");
private static final ParseField ROUTING = new ParseField("routing");
Expand Down Expand Up @@ -248,6 +249,11 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
return builder;
}

@Override
public String toString() {
Copy link
Member Author

Choose a reason for hiding this comment

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

I added this because during debugging #30911 I found it really useful to have a readable toString() output for the Alias class.

Copy link
Member

Choose a reason for hiding this comment

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

+1

return Strings.toString(this);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ protected PutIndexTemplateRequest createTestInstance() {
request.patterns(Arrays.asList(generateRandomStringArray(20, 100, false, false)));
int numAlias = between(0, 5);
for (int i = 0; i < numAlias; i++) {
Alias alias = new Alias(randomRealisticUnicodeOfLengthBetween(1, 10));
// some ASCII or Latin-1 control characters, especially newline, can lead to
// problems with yaml parsers, that's why we filter them here (see #30911)
Alias alias = new Alias(randomRealisticUnicodeOfLengthBetween(1, 10).replaceAll("\\p{Cc}", ""));
if (randomBoolean()) {
alias.indexRouting(randomRealisticUnicodeOfLengthBetween(1, 10));
}
Expand Down