55using DatabaseBenchmark . Databases . Elasticsearch . Interfaces ;
66using DatabaseBenchmark . DataSources . Interfaces ;
77using DatabaseBenchmark . Model ;
8- using Nest ;
8+ using Elastic . Clients . Elasticsearch ;
9+ using Elastic . Clients . Elasticsearch . Mapping ;
910using System . Text ;
1011using RawQuery = DatabaseBenchmark . Model . RawQuery ;
1112
@@ -33,16 +34,16 @@ public void CreateTable(Table table, bool dropExisting)
3334
3435 if ( dropExisting )
3536 {
36- var exists = client . Indices . Exists ( table . Name ) ;
37- if ( exists . Exists )
37+ var existsResponse = client . Indices . ExistsAsync ( table . Name ) . GetAwaiter ( ) . GetResult ( ) ;
38+ if ( existsResponse . Exists )
3839 {
39- client . Indices . Delete ( table . Name ) ;
40+ client . Indices . DeleteAsync ( table . Name ) . GetAwaiter ( ) . GetResult ( ) ;
4041 }
4142 }
4243
43- client . Indices . CreateAsync ( table . Name , ci => ci
44- . Map ( md => md
45- . Properties ( pd => BuildProperties ( table , pd ) ) ) ) . Wait ( ) ;
44+ client . Indices . CreateAsync ( table . Name , c => c
45+ . Mappings ( m => m
46+ . Properties ( BuildProperties ( table ) ) ) ) . GetAwaiter ( ) . GetResult ( ) ;
4647 }
4748
4849 public IDataImporter CreateDataImporter ( Table table , IDataSource source , int batchSize )
@@ -58,7 +59,7 @@ public IDataImporter CreateDataImporter(Table table, IDataSource source, int bat
5859 . Environment ( _environment )
5960 . Customize ( ( container , lifestyle ) =>
6061 {
61- container . Register < IElasticClient > ( CreateClient , lifestyle ) ;
62+ container . Register < ElasticsearchClient > ( CreateClient , lifestyle ) ;
6263 } )
6364 . Build ( ) ;
6465 }
@@ -74,32 +75,34 @@ public IQueryExecutorFactory CreateInsertExecutorFactory(Table table, IDataSourc
7475
7576 public void ExecuteScript ( string script ) => throw new InputArgumentException ( "Custom scripts are not supported for Elasticsearch" ) ;
7677
77- private ElasticClient CreateClient ( )
78+ private ElasticsearchClient CreateClient ( )
7879 {
79- var connectionSettings = new ConnectionSettings ( new Uri ( ConnectionString ) )
80+ var settings = new ElasticsearchClientSettings ( new Uri ( ConnectionString ) )
8081 . ThrowExceptions ( ) ;
8182
8283 if ( _environment . TraceQueries || _environment . TraceResults )
8384 {
84- connectionSettings . EnableDebugMode ( response =>
85+ settings . EnableDebugMode ( details =>
8586 {
86- if ( _environment . TraceQueries && response . RequestBodyInBytes != null )
87+ if ( _environment . TraceQueries && details . RequestBodyInBytes != null )
8788 {
88- _environment . WriteLine ( Encoding . UTF8 . GetString ( response . RequestBodyInBytes ) ) ;
89+ _environment . WriteLine ( Encoding . UTF8 . GetString ( details . RequestBodyInBytes ) ) ;
8990 }
9091
91- if ( _environment . TraceResults && response . ResponseBodyInBytes != null )
92+ if ( _environment . TraceResults && details . ResponseBodyInBytes != null )
9293 {
93- _environment . WriteLine ( Encoding . UTF8 . GetString ( response . ResponseBodyInBytes ) ) ;
94+ _environment . WriteLine ( Encoding . UTF8 . GetString ( details . ResponseBodyInBytes ) ) ;
9495 }
9596 } ) ;
9697 }
9798
98- return new ElasticClient ( connectionSettings ) ;
99+ return new ElasticsearchClient ( settings ) ;
99100 }
100101
101- private PropertiesDescriptor < object > BuildProperties ( Table table , PropertiesDescriptor < object > propertiesDescriptor )
102+ private Properties BuildProperties ( Table table )
102103 {
104+ var properties = new Properties ( ) ;
105+
103106 foreach ( var column in table . Columns )
104107 {
105108 if ( column . DatabaseGenerated )
@@ -108,47 +111,22 @@ private PropertiesDescriptor<object> BuildProperties(Table table, PropertiesDesc
108111 continue ;
109112 }
110113
111- switch ( column . Type )
114+ IProperty property = column . Type switch
112115 {
113- case ColumnType . Boolean :
114- propertiesDescriptor . Boolean ( bpd => bpd
115- . Name ( column . Name )
116- . Index ( column . Queryable ) ) ;
117- break ;
118- case ColumnType . Guid :
119- case ColumnType . String :
120- propertiesDescriptor . Keyword ( kpd => kpd
121- . Name ( column . Name )
122- . Index ( column . Queryable ) ) ;
123- break ;
124- case ColumnType . Double :
125- propertiesDescriptor . Number ( npd => npd
126- . Name ( column . Name )
127- . Type ( NumberType . Double )
128- . Index ( column . Queryable ) ) ;
129- break ;
130- case ColumnType . Integer :
131- propertiesDescriptor . Number ( npd => npd
132- . Name ( column . Name )
133- . Type ( NumberType . Integer )
134- . Index ( column . Queryable ) ) ;
135- break ;
136- case ColumnType . Text :
137- propertiesDescriptor . Text ( tpd => tpd
138- . Name ( column . Name )
139- . Index ( column . Queryable ) ) ;
140- break ;
141- case ColumnType . DateTime :
142- propertiesDescriptor . Date ( dpd => dpd
143- . Name ( column . Name )
144- . Index ( column . Queryable ) ) ;
145- break ;
146- default :
147- throw new InputArgumentException ( $ "Unknown column type \" { column . Type } \" ") ;
148- }
116+ ColumnType . Boolean => new BooleanProperty { Index = column . Queryable } ,
117+ ColumnType . Guid => new KeywordProperty { Index = column . Queryable } ,
118+ ColumnType . String => new KeywordProperty { Index = column . Queryable } ,
119+ ColumnType . Double => new DoubleNumberProperty { Index = column . Queryable } ,
120+ ColumnType . Integer => new IntegerNumberProperty { Index = column . Queryable } ,
121+ ColumnType . Text => new TextProperty { Index = column . Queryable } ,
122+ ColumnType . DateTime => new DateProperty { Index = column . Queryable } ,
123+ _ => throw new InputArgumentException ( $ "Unknown column type \" { column . Type } \" ")
124+ } ;
125+
126+ properties . Add ( column . Name , property ) ;
149127 }
150128
151- return propertiesDescriptor ;
129+ return properties ;
152130 }
153131
154132 private static Table NormalizeNames ( Table table )
0 commit comments