コード例 #1
0
    public static void toXContent(
        AliasMetaData aliasMetaData, XContentBuilder builder, ToXContent.Params params)
        throws IOException {
      builder.startObject(aliasMetaData.alias(), XContentBuilder.FieldCaseConversion.NONE);

      boolean binary = params.paramAsBoolean("binary", false);

      if (aliasMetaData.filter() != null) {
        if (binary) {
          builder.field("filter", aliasMetaData.filter.compressed());
        } else {
          byte[] data = aliasMetaData.filter().uncompressed();
          XContentParser parser = XContentFactory.xContent(data).createParser(data);
          Map<String, Object> filter = parser.mapOrdered();
          parser.close();
          builder.field("filter", filter);
        }
      }
      if (aliasMetaData.indexRouting() != null) {
        builder.field("index_routing", aliasMetaData.indexRouting());
      }
      if (aliasMetaData.searchRouting() != null) {
        builder.field("search_routing", aliasMetaData.searchRouting());
      }

      builder.endObject();
    }
コード例 #2
0
  public void testMultipleAliasesPrecedence() throws Exception {
    client()
        .admin()
        .indices()
        .preparePutTemplate("template1")
        .setTemplate("*")
        .setOrder(0)
        .addAlias(new Alias("alias1"))
        .addAlias(new Alias("{index}-alias"))
        .addAlias(
            new Alias("alias3")
                .filter(QueryBuilders.boolQuery().mustNot(QueryBuilders.existsQuery("test"))))
        .addAlias(new Alias("alias4"))
        .get();

    client()
        .admin()
        .indices()
        .preparePutTemplate("template2")
        .setTemplate("te*")
        .setOrder(1)
        .addAlias(new Alias("alias1").routing("test"))
        .addAlias(new Alias("alias3"))
        .get();

    assertAcked(
        prepareCreate("test").addAlias(new Alias("test-alias").searchRouting("test-routing")));

    ensureGreen();

    GetAliasesResponse getAliasesResponse =
        client().admin().indices().prepareGetAliases().addIndices("test").get();
    assertThat(getAliasesResponse.getAliases().get("test").size(), equalTo(4));

    for (AliasMetaData aliasMetaData : getAliasesResponse.getAliases().get("test")) {
      assertThat(
          aliasMetaData.alias(),
          anyOf(equalTo("alias1"), equalTo("test-alias"), equalTo("alias3"), equalTo("alias4")));
      if ("alias1".equals(aliasMetaData.alias())) {
        assertThat(aliasMetaData.indexRouting(), equalTo("test"));
        assertThat(aliasMetaData.searchRouting(), equalTo("test"));
      } else if ("alias3".equals(aliasMetaData.alias())) {
        assertThat(aliasMetaData.filter(), nullValue());
      } else if ("test-alias".equals(aliasMetaData.alias())) {
        assertThat(aliasMetaData.indexRouting(), nullValue());
        assertThat(aliasMetaData.searchRouting(), equalTo("test-routing"));
      }
    }
  }
コード例 #3
0
 public static void writeTo(AliasMetaData aliasMetaData, StreamOutput out) throws IOException {
   out.writeString(aliasMetaData.alias());
   if (aliasMetaData.filter() != null) {
     out.writeBoolean(true);
     aliasMetaData.filter.writeTo(out);
   } else {
     out.writeBoolean(false);
   }
   if (aliasMetaData.indexRouting() != null) {
     out.writeBoolean(true);
     out.writeString(aliasMetaData.indexRouting());
   } else {
     out.writeBoolean(false);
   }
   if (aliasMetaData.searchRouting() != null) {
     out.writeBoolean(true);
     out.writeString(aliasMetaData.searchRouting());
   } else {
     out.writeBoolean(false);
   }
 }
コード例 #4
0
 private AliasMetaData(AliasMetaData aliasMetaData, String alias) {
   this(
       alias, aliasMetaData.filter(), aliasMetaData.indexRouting(), aliasMetaData.searchRouting());
 }
コード例 #5
0
 public Builder(AliasMetaData aliasMetaData) {
   this(aliasMetaData.alias());
   filter = aliasMetaData.filter();
   indexRouting = aliasMetaData.indexRouting();
   searchRouting = aliasMetaData.searchRouting();
 }