Beispiel #1
0
 public ElasticGateway(IElasticClient esClient)
 {
     _esClient = esClient;
     _indices  = Indices.Index(new List <IndexName> {
         "hackney_addresses", "national_addresses"
     });
 }
        public void Initialize(string serverUri)
        {
            _nodeLocation = new Uri(serverUri);
            _settings     = new ConnectionSettings(_nodeLocation)
                            .DefaultMappingFor <Drug>(m => m.IndexName(Drug.IndexName)
                                                      .IdProperty("Id"))
                            .DefaultMappingFor <Application>(m => m.IndexName(Application.IndexName)
                                                             .IdProperty("Id"))
                            .DefaultMappingFor <Exclusivity>(m => m.IndexName(Exclusivity.IndexName)
                                                             .IdProperty("Id"))
                            .DefaultMappingFor <FederalUpperLimit>(m => m.IndexName(FederalUpperLimit.IndexName)
                                                                   .IdProperty("Id"))
                            .DefaultMappingFor <Nadac>(m => m.IndexName(Nadac.IndexName)
                                                       .IdProperty("Id"))
                            .DefaultMappingFor <Package>(m => m.IndexName(Package.IndexName)
                                                         .IdProperty("Id"))
                            .DefaultMappingFor <Patent>(m => m.IndexName(Patent.IndexName)
                                                        .IdProperty("Id"))
                            .DefaultMappingFor <PharmaClass>(m => m.IndexName(PharmaClass.IndexName)
                                                             .IdProperty("Id"))
                            .DefaultMappingFor <StateDrugUtilization>(m => m.IndexName(StateDrugUtilization.IndexName)
                                                                      .IdProperty("Id"));

            _resolver = new IndexNameResolver(_settings);
            _client   = new ElasticClient(_settings);

            Indices.ManyIndices indexesToDelete = Indices.Index(
                Drug.IndexName,
                Application.IndexName,
                Exclusivity.IndexName,
                FederalUpperLimit.IndexName,
                Nadac.IndexName,
                Package.IndexName,
                Patent.IndexName,
                PharmaClass.IndexName,
                StateDrugUtilization.IndexName
                );

            _client.DeleteIndex(indexesToDelete);

            _client.CreateIndex(Drug.IndexName,
                                x => x.Settings(s => s.NumberOfShards(3))
                                .Mappings(m => m
                                          .Map <Drug>(mt => mt.AutoMap())));
            _client.CreateIndex(Application.IndexName,
                                x => x.Settings(s => s.NumberOfShards(3))
                                .Mappings(m => m
                                          .Map <Application>(mt => mt.AutoMap()))
                                );
            _client.CreateIndex(Exclusivity.IndexName,
                                x => x.Settings(s => s.NumberOfShards(3))
                                .Mappings(m => m
                                          .Map <Exclusivity>(mt => mt.AutoMap()))
                                );
            _client.CreateIndex(FederalUpperLimit.IndexName,
                                x => x.Settings(s => s.NumberOfShards(3))
                                .Mappings(m => m
                                          .Map <FederalUpperLimit>(mt => mt.AutoMap()))
                                );
            _client.CreateIndex(Nadac.IndexName,
                                x => x.Settings(s => s.NumberOfShards(3))
                                .Mappings(m => m
                                          .Map <Nadac>(mt => mt.AutoMap()))
                                );
            _client.CreateIndex(Package.IndexName,
                                x => x.Settings(s => s.NumberOfShards(3))
                                .Mappings(m => m
                                          .Map <Package>(mt => mt.AutoMap()))
                                );
            _client.CreateIndex(Patent.IndexName,
                                x => x.Settings(s => s.NumberOfShards(3))
                                .Mappings(m => m
                                          .Map <Patent>(mt => mt.AutoMap()))
                                );
            _client.CreateIndex(PharmaClass.IndexName,
                                x => x.Settings(s => s.NumberOfShards(3))
                                .Mappings(m => m
                                          .Map <PharmaClass>(mt => mt.AutoMap()))
                                );
            _client.CreateIndex(StateDrugUtilization.IndexName,
                                x => x.Settings(s => s.NumberOfShards(3))
                                .Mappings(m => m
                                          .Map <StateDrugUtilization>(mt => mt.AutoMap()))
                                );
        }