public void CreateAliasForIndex2()
        {
            var indexAliasDtoTest = new IndexAliasDtoTest {
                Id = 1, Description = "Test index for aliases"
            };

            var aliasParameters = new AliasParameters
            {
                Actions = new List <AliasBaseParameters>
                {
                    new AliasAddParameters("test2", "indexaliasdtotests"),
                    new AliasAddParameters("test3", "indexaliasdtotests")
                }
            };

            using (var context = new ElasticsearchContext(ConnectionString, _elasticsearchMappingResolver))
            {
                context.AddUpdateDocument(indexAliasDtoTest, indexAliasDtoTest.Id);
                context.SaveChanges();

                var result = context.Alias(aliasParameters.ToString());
                Assert.IsTrue(result);

                Assert.IsTrue(context.AliasExists("test2"));
                Assert.IsTrue(context.AliasExists("test3"));
            }
        }
        public void RemoveAliasForIndex2()
        {
            var aliasParameters = new AliasParameters
            {
                Actions = new List <AliasBaseParameters>
                {
                    new AliasRemoveParameters("test", "indexaliasdtotests")
                }
            };

            var indexAliasDtoTest = new IndexAliasDtoTest {
                Id = 1, Description = "Test index for aliases"
            };

            using (var context = new ElasticsearchContext(ConnectionString, _elasticsearchMappingResolver))
            {
                context.AddUpdateDocument(indexAliasDtoTest, indexAliasDtoTest.Id);
                context.SaveChanges();

                var resultCreate = context.AliasCreateForIndex("test", "indexaliasdtotests");
                Assert.True(resultCreate);

                var resultRemove = context.Alias(aliasParameters);
                Assert.True(resultRemove);
            }
        }
        public void CreateAliasForIndex3()
        {
            var indexAliasDtoTest3 = new IndexAliasDtoTest {
                Id = 3, Description = "no"
            };
            var indexAliasDtoTest4 = new IndexAliasDtoTest {
                Id = 4, Description = "boo"
            };
            var indexAliasDtoTest5 = new IndexAliasDtoTest {
                Id = 5, Description = "boo"
            };

            var aliasParameters = new AliasParameters
            {
                Actions = new List <AliasBaseParameters>
                {
                    new AliasAddParameters("test4", "indexaliasdtotests")
                    {
                        Routing = "newroute",
                        Filter  = new TermFilter("description", "boo")                       // "{ \"term\" : { \"description\" : \"boo\" } }"
                    }
                }
            };

            const bool userDefinedRouting = true;
            var        elasticsearchSerializerConfiguration = new ElasticsearchSerializerConfiguration(_elasticsearchMappingResolver,
                                                                                                       true, false, userDefinedRouting);

            using (var context = new ElasticsearchContext(ConnectionString, elasticsearchSerializerConfiguration))
            {
                context.AddUpdateDocument(indexAliasDtoTest3, indexAliasDtoTest3.Id, new RoutingDefinition {
                    RoutingId = "newroute"
                });
                context.AddUpdateDocument(indexAliasDtoTest4, indexAliasDtoTest4.Id, new RoutingDefinition {
                    RoutingId = "newroute"
                });
                context.AddUpdateDocument(indexAliasDtoTest5, indexAliasDtoTest5.Id, new RoutingDefinition {
                    RoutingId = "newroute"
                });
                context.SaveChanges();

                var result = context.Alias(aliasParameters.ToString());
                Assert.IsTrue(result);

                Assert.IsTrue(context.AliasExists("test4"));

                // using the index
                var doc3 = context.GetDocument <IndexAliasDtoTest>(3, new RoutingDefinition {
                    RoutingId = "newroute"
                });
                Assert.IsTrue(doc3.Id == 3);
                var doc4 = context.GetDocument <IndexAliasDtoTest>(4, new RoutingDefinition {
                    RoutingId = "newroute"
                });
                Assert.IsTrue(doc4.Id == 4);
            }

            IElasticsearchMappingResolver elasticsearchMappingResolver = new ElasticsearchMappingResolver();

            elasticsearchMappingResolver.AddElasticSearchMappingForEntityType(
                typeof(IndexAliasDtoTest),
                MappingUtils.GetElasticsearchMapping <IndexAliasDtoTest>("test4", "indexaliasdtotest")
                );

            using (var context = new ElasticsearchContext(ConnectionString, elasticsearchMappingResolver))
            {
                // using the alias
                var xx = context.GetDocument <IndexAliasDtoTest>(4);
                Assert.IsTrue(xx.Id == 4);

                // should not be found due to filter
                var result = context.SearchById <IndexAliasDtoTest>(3);
                Assert.IsNull(result);
            }
        }