コード例 #1
0
        public async void ConnectionPool_ThrowOnServerExceptions_ThrowsElasticsearchServerException_Async()
        {
            var uris = new []
            {
                ElasticsearchConfiguration.CreateBaseUri(9200),
                ElasticsearchConfiguration.CreateBaseUri(9200),
                ElasticsearchConfiguration.CreateBaseUri(9200),
            };
            var connectionPool = new StaticConnectionPool(uris);
            var client         = new ElasticClient(new ConnectionSettings(connectionPool)
                                                   .ThrowOnElasticsearchServerExceptions()
                                                   .SetTimeout(1000)
                                                   );

            try
            {
                var index  = ElasticsearchConfiguration.NewUniqueIndexName();
                var create = await client.CreateIndexAsync(i => i.Index(index));

                var close = await client.CloseIndexAsync(i => i.Index(index));

                var result = await client.SearchAsync <ElasticsearchProject>(s => s.Index(index));
            }
            catch (ElasticsearchServerException)
            {
                Assert.Pass("ElasticearchServerException caught");
            }
            catch (Exception e)
            {
                Assert.Fail("Did not expect exception of type {0} to be caught", e.GetType().Name);
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: onfjp/dd-trace-dotnet
        private static List <Func <object> > IndexCommandsAsync(ElasticClient elastic)
        {
            return(new List <Func <object> >
            {
                () => elastic.CreateIndexAsync("test_index_1"),
                () => elastic.IndexExistsAsync("test_index_1"),
                () => elastic.UpdateIndexSettingsAsync(new UpdateIndexSettingsRequest("test_index_1")
                {
                    IndexSettings = new IndexSettings()
                    {
                        Sorting = new SortingSettings
                        {
                            Fields = new Field("Title"),
                        },
                    },
                }),
                () => elastic.AliasAsync(new BulkAliasRequest
                {
                    Actions = new List <IAliasAction>
                    {
                        new AliasAddAction
                        {
                            Add = new AliasAddOperation
                            {
                                Index = "test_index_1",
                                Alias = "test_index_2",
                            },
                        },
                    },
                }),
                () => elastic.GetAliasesPointingToIndexAsync("test_index_1"),
                () => elastic.PutAliasAsync("test_index_1", "test_index_3"),
                () => elastic.AliasExistsAsync(new AliasExistsRequest("test_index_1")),
                () => elastic.DeleteAliasAsync(new DeleteAliasRequest("test_index_1", "test_index_3")),
                () => elastic.DeleteAliasAsync(new DeleteAliasRequest("test_index_1", "test_index_2")),
                () => elastic.CreateIndexAsync("test_index_4"),
#if (ELASTICSEARCH_6_1 && !DEFAULT_SAMPLES)
                () => elastic.SplitIndexAsync("test_index_1", "test_index_4"),
#endif
                () => elastic.DeleteIndexAsync("test_index_4"),
                () => elastic.CloseIndexAsync("test_index_1"),
                () => elastic.OpenIndexAsync("test_index_1"),
                () => elastic.PutIndexTemplateAsync(new PutIndexTemplateRequest("test_template_1")),
                () => elastic.IndexTemplateExistsAsync("test_template_1"),
                () => elastic.DeleteIndexTemplateAsync("test_template_1"),
                () => elastic.IndicesShardStoresAsync(),
                () => elastic.IndicesStatsAsync("test_index_1"),
                () => elastic.DeleteIndexAsync("test_index_1"),
                () => elastic.GetAliasAsync(new GetAliasRequest()),
            });
        }
コード例 #3
0
 private static List <Func <object> > IndexCommandsAsync(ElasticClient elastic)
 {
     return(new List <Func <object> >
     {
         () => elastic.CreateIndexAsync("test_index_1"),
         () => elastic.IndexExistsAsync("test_index_1"),
         () => elastic.UpdateIndexSettingsAsync(new UpdateIndexSettingsRequest("test_index_1")
         {
             IndexSettings = new IndexSettings()
             {
                 // V6 Feature
                 // Sorting = new SortingSettings
                 // {
                 //     Fields = new Field("Title"),
                 // },
             },
         }),
         () => elastic.AliasAsync(new BulkAliasRequest
         {
             Actions = new List <IAliasAction>
             {
                 new AliasAddAction
                 {
                     Add = new AliasAddOperation
                     {
                         Index = "test_index_1",
                         Alias = "test_index_2",
                     },
                 },
             },
         }),
         () => elastic.GetAliasesPointingToIndexAsync("test_index_1"),
         () => elastic.PutAliasAsync("test_index_1", "test_index_3"),
         () => elastic.DeleteAliasAsync(new DeleteAliasRequest("test_index_1", "test_index_3")),
         () => elastic.DeleteAliasAsync(new DeleteAliasRequest("test_index_1", "test_index_2")),
         () => elastic.CreateIndexAsync("test_index_4"),
         () => elastic.DeleteIndexAsync("test_index_4"),
         () => elastic.CloseIndexAsync("test_index_1"),
         () => elastic.OpenIndexAsync("test_index_1"),
         () => elastic.PutIndexTemplateAsync(new PutIndexTemplateRequest("test_template_1")),
         () => elastic.IndexTemplateExistsAsync("test_template_1"),
         () => elastic.DeleteIndexTemplateAsync("test_template_1"),
         () => elastic.IndicesShardStoresAsync(),
         () => elastic.IndicesStatsAsync("test_index_1"),
         () => elastic.DeleteIndexAsync("test_index_1"),
         () => elastic.GetAliasAsync(new GetAliasRequest()),
         () => elastic.ReindexOnServerAsync(new ReindexOnServerRequest
         {
             Source = new ReindexSource
             {
                 Remote = new RemoteSource
                 {
                     Host = new Uri("http://" + Host()),
                     Username = "******",
                     Password = "******"
                 },
                 Index = "some_index",
                 Size = 10
             },
             Destination = new ReindexDestination
             {
                 Index = "some_index_clone",
             }
         })
     });
 }
コード例 #4
0
		public async void ConnectionPool_ThrowOnServerExceptions_ThrowsElasticsearchServerException_Async()
		{
			var uris = new []
			{
				ElasticsearchConfiguration.CreateBaseUri(9200),
				ElasticsearchConfiguration.CreateBaseUri(9200),
				ElasticsearchConfiguration.CreateBaseUri(9200),
			};
			var connectionPool = new StaticConnectionPool(uris);
			var client = new ElasticClient(new ConnectionSettings(connectionPool)
				.ThrowOnElasticsearchServerExceptions()
				.SetTimeout(1000)
			);
			try
			{

				var index = ElasticsearchConfiguration.NewUniqueIndexName();
				var create = await client.CreateIndexAsync(i=>i.Index(index));
				var close = await client.CloseIndexAsync(i=>i.Index(index));
				var result = await client.SearchAsync<ElasticsearchProject>(s => s.Index(index));
			}
			catch (ElasticsearchServerException)
			{
				Assert.Pass("ElasticearchServerException caught");
			}
			catch (Exception e)
			{
				Assert.Fail("Did not expect exception of type {0} to be caught", e.GetType().Name);
			}
		}