protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values)
        {
            var seeder = new DefaultSeeder(Cluster.Client);

            seeder.SeedNode();

            // get a suitable load of projects in order to get a decent task status out
            var bulkResponse = client.IndexMany(Project.Generator.Generate(20000));

            if (!bulkResponse.IsValid)
            {
                throw new Exception("failure in setting up integration");
            }

            var response = client.ReindexOnServer(r => r
                                                  .Source(s => s
                                                          .Index(Infer.Index <Project>())
                                                          .Type(typeof(Project))
                                                          )
                                                  .Destination(d => d
                                                               .Index("tasks-list-projects")
                                                               .OpType(OpType.Create)
                                                               )
                                                  .Conflicts(Conflicts.Proceed)
                                                  .WaitForCompletion(false)
                                                  .Refresh()
                                                  );

            _taskId = response.Task;
        }
示例#2
0
        public void AddSimpleTestData()
        {
            Client.DeleteIndex(Infer.Index <Car>());
            Client.CreateIndex(Infer.Index <Car>(), x => x.Mappings(
                                   m => m.Map <Car>(t => t
                                                    .Properties(prop => prop.String(str => str.Name(s => s.EngineType).Index(FieldIndexOption.NotAnalyzed))))));

            for (int i = 0; i < 10; i++)
            {
                var car = new Car
                {
                    Timestamp          = new DateTime(2010, i + 1, 1),
                    Name               = "Car" + i,
                    Price              = 10,
                    Sold               = i % 2 == 0 ? true : false,
                    CarType            = "Type" + i % 3,
                    Length             = i,
                    EngineType         = i % 2 == 0 ? EngineType.Diesel : EngineType.Standard,
                    Weight             = 5,
                    ConditionalRanking = i % 2 == 0 ? null : (int?)i,
                    Description        = "Desc" + i,
                };

                Client.Index(car);
            }
            Client.Flush(CarIndex);
        }
        [U] public void IndexName()
        {
            IndexName fromString = "index-1";
            var       fromType   = Infer.Index <Project>();

            DebugFor(fromString).Should().Be("index-1");
            DebugFor(fromType).Should().Be("IndexName for typeof: Project");
        }
        [U] public void IndicesDebug()
        {
            Nest.Indices all          = Nest.Indices.All;
            Nest.Indices fromTypeName = Infer.Index <Project>();
            Nest.Indices fromType     = typeof(CommitActivity);
            Nest.Indices multiple     = Infer.Index("someindex").And <Project>();

            DebugFor(all).Should().Be("_all");
            DebugFor(fromTypeName).Should().Be($"Count: 1 [(1: IndexName for typeof: {nameof(Project)})]");
            DebugFor(fromType).Should().Be($"Count: 1 [(1: IndexName for typeof: {nameof(CommitActivity)})]");
            DebugFor(multiple).Should().Be($"Count: 2 [(1: someindex),(2: IndexName for typeof: {nameof(Project)})]");
        }
示例#5
0
        private void CreateDeveloperIndex()
        {
            var createDeveloperIndex = this.Client.CreateIndex(Infer.Index <Developer>(), c => c
                                                               .Mappings(map => map
                                                                         .Map <Developer>(m => m
                                                                                          .AutoMap()
                                                                                          .Properties(DeveloperProperties)
                                                                                          )
                                                                         )
                                                               );

            createDeveloperIndex.IsValid.Should().BeTrue();
        }
示例#6
0
        public void TopHits_Sorted_SettingSize()
        {
            Client.DeleteIndex(Infer.Index <User>());
            Client.CreateIndex(Infer.Index <User>());
            for (int i = 0; i < 100; i++)
            {
                var user = new User
                {
                    Name        = "User" + i,
                    Nationality = "Nationality" + i % 10,
                    Age         = (i + 1) % 10
                };

                Client.Index(user);
            }
            Client.Flush(Infer.Index <User>());

            var result = Client.Search <User>(search => search.Aggregations(agg => agg
                                                                            // get 40 first users, sort by name. for each user retrieve name and email
                                                                            .SortedTopHits(40, x => x.Name, SortType.Ascending, x => x.Name, y => y.Email)
                                                                            .SortedTopHits(40, x => x.Name, SortType.Descending, x => x.Name, y => y.Email)
                                                                            .SumBy(x => x.Age)
                                                                            .GroupBy(b => b.Nationality))
                                              );

            var userByNationality = result.Aggs.GetGroupBy <User>(x => x.Nationality).ToList();

            Check.That(userByNationality).HasSize(10);
            var firstNotionality = userByNationality.Single(x => x.Key == "nationality0");

            var ascendingHits = firstNotionality.GetSortedTopHits <User>(x => x.Name, SortType.Ascending).ToList();

            Check.That(ascendingHits).HasSize(10);
            Check.That(ascendingHits[0].Name).IsNotNull();

            Check.That(firstNotionality.GetSum <User, int>(x => x.Age)).Equals(10);
            Check.That(ascendingHits[0].Name).Equals("User0");
            Check.That(ascendingHits[1].Name).Equals("User10");
            Check.That(ascendingHits[2].Name).Equals("User20");
            Check.That(ascendingHits[3].Name).Equals("User30");

            var descendingHits = firstNotionality.GetSortedTopHits <User>(x => x.Name, SortType.Descending).ToList();

            Check.That(descendingHits).HasSize(10);
            Check.That(descendingHits[0].Name).IsNotNull();

            Check.That(descendingHits[0].Name).Equals("User90");
            Check.That(descendingHits[1].Name).Equals("User80");
            Check.That(descendingHits[2].Name).Equals("User70");
            Check.That(descendingHits[3].Name).Equals("User60");
        }
 public DocumentsCoordinatedTests(WritableCluster cluster, EndpointUsage usage) : base(
         new CoordinatedUsage(cluster, usage)
 {
     {
         IndexDocumentStep, u =>
         u.Calls <IndexRequestDescriptor <Project>, IndexRequest <Project>, IndexResponse>(
             v => new IndexRequest <Project>(Project.Instance, v) { Routing = "route" },
             (v, d) => d,
             (v, c, f) => c.Index(Project.Instance, "project", f => f.Id(v).Routing("route")),                                 // TODO: Should be able to set ID in the Index method and should be able to infer the index name + route
             (v, c, f) => c.IndexAsync(Project.Instance, "project", f => f.Id(v).Routing("route")),
             (_, c, r) => c.Index(r),
             (_, c, r) => c.IndexAsync(r)
             )
     },
     {
         DocumentExistsStep, u =>
         u.Calls <ExistsRequestDescriptor, ExistsRequest, ExistsResponse>(
             v => new ExistsRequest(typeof(Project), v) { Routing = "route" },
             (v, d) => d.Routing("route"),
             (v, c, f) => c.Exists(Infer.Index <Project>(), v, f),
             (v, c, f) => c.ExistsAsync(Infer.Index <Project>(), v, f),
             (_, c, r) => c.Exists(r),
             (_, c, r) => c.ExistsAsync(r)
             )
     },
     {
         GetDocumentStep, u =>
         u.Calls <GetRequestDescriptor <Project>, GetRequest, GetResponse <Project> >(
             v => new GetRequest(typeof(Project), v) { Routing = "route" },
             (v, d) => d.Routing("route"),
             (v, c, f) => c.Get(Infer.Index <Project>(), v, f),
             (v, c, f) => c.GetAsync(Infer.Index <Project>(), v, f),
             (_, c, r) => c.Get <Project>(r),
             (_, c, r) => c.GetAsync <Project>(r)
             )
     },
     {
         DeleteDocumentStep, u =>
         u.Calls <DeleteRequestDescriptor, DeleteRequest, DeleteResponse>(
             v => new DeleteRequest(Infer.Index <Project>(), v) { Routing = "route" },
             (v, d) => d.Routing("route"),
             (v, c, f) => c.Delete(Infer.Index <Project>(), v, f),
             (v, c, f) => c.DeleteAsync(Infer.Index <Project>(), v, f),
             (_, c, r) => c.Delete(r),
             (_, c, r) => c.DeleteAsync(r)
             )
     },
 })
 {
 }
示例#8
0
        public void TopHits_In_Double_GroupBy()
        {
            Client.DeleteIndex(Infer.Index <User>());
            Client.CreateIndex(Infer.Index <User>());
            for (int i = 0; i < 250; i++)
            {
                var user = new User
                {
                    Name        = "User" + i,
                    Nationality = "Nationality" + i % 2,
                    Active      = i % 3 == 0
                };

                Client.Index(user);
            }
            Client.Flush(Infer.Index <User>());

            var result = Client.Search <User>(search => search.Aggregations(agg => agg
                                                                            .TopHits(40, x => x.Name)
                                                                            .GroupBy(b => b.Active)
                                                                            .GroupBy(b => b.Nationality))
                                              );

            var userByNationality = result.Aggs.GetGroupBy <User>(x => x.Nationality).ToList();

            Check.That(userByNationality).HasSize(2);
            foreach (var nationality in userByNationality)
            {
                var byActive = nationality.GetGroupBy <User>(x => x.Active).ToList();

                var activeUsers  = byActive[0];
                var inactiveUser = byActive[1];


                var hits = activeUsers.GetTopHits <User>().ToList();
                Check.That(hits).HasSize(40);
                Check.That(hits[0].Name).IsNotNull();

                hits = inactiveUser.GetTopHits <User>().ToList();

                Check.That(hits).HasSize(40);
                Check.That(hits[0].Name).IsNotNull();
            }
        }
示例#9
0
        public override async Task ProfileAsync(IElasticClient client, ColoredConsoleWriter output)
        {
            for (var i = 0; i < _iterations; i++)
            {
                var bulkResponse = await client.BulkAsync(b => b
                                                          .IndexMany(Developer.Generator.Generate(_itemsPerIteration), (bd, d) => bd
                                                                     .Index(Infer.Index <Developer>())
                                                                     .Document(d)
                                                                     )).ConfigureAwait(false);

                if (!bulkResponse.IsValid)
                {
                    if (bulkResponse.Errors)
                    {
                        foreach (var error in bulkResponse.ItemsWithErrors)
                        {
                            output.WriteOrange($"error with id {error.Id}. message: {error.Error.Reason}");
                        }
                    }
                }
            }
        }
示例#10
0
        public void Terms_Aggregation_Big_Size()
        {
            Client.DeleteIndex(Infer.Index <User>());
            Client.CreateIndex(Infer.Index <User>());
            for (int i = 0; i < 200; i++)
            {
                var user = new User
                {
                    Name        = "User" + i,
                    Nationality = "Nationality" + i % 20
                };


                Client.Index(user);
            }
            Client.Flush(Infer.Index <User>());

            var result = Client.Search <User>(sc => sc.Aggregations(agg => agg.DistinctBy(x => x.Nationality)));

            var nationalities = result.Aggs.GetDistinct <User, string>(x => x.Nationality).ToList();

            Check.That(nationalities).IsNotNull();
            Check.That(nationalities).HasSize(20);
        }
示例#11
0
 private Task <CreateIndexResponse> CreateDeveloperIndexAsync() => Client.Indices.CreateAsync(Infer.Index <Developer>(), c => c
                                                                                              .Map <Developer>(m => m
                                                                                                               .AutoMap()
                                                                                                               .Properties(DeveloperProperties)
                                                                                                               )
                                                                                              );
示例#12
0
        public void FullExample_InitializerSyntax_Search()
        {
            QueryContainer query = new TermQuery()
            {
                Field = Property.Path <ElasticsearchProject>(p => p.Name),
                Value = "value"
            } && new PrefixQuery()
            {
                Field   = "prefix_field",
                Value   = "prefi",
                Rewrite = RewriteMultiTerm.ConstantScoreBoolean
            };

            var result = _client.Search <ElasticsearchProject>(new SearchRequest
            {
                From     = 0,
                Size     = 20,
                MinScore = 2.1,
                Rescore  = new Rescore
                {
                    WindowSize = 10,
                    Query      = new RescoreQuery
                    {
                        Query = new TermQuery()
                        {
                        }.ToContainer(),
                        QueryWeight        = 1.2,
                        RescoreQueryWeight = 2.1
                    }
                },
                Fields = new[]
                {
                    "field",
                    Property.Path <ElasticsearchProject>(p => p.Name)
                },
                Query  = query,
                Filter = new FilterContainer(new BoolFilter
                {
                    Cache = true,
                    Must  = new FilterContainer[]
                    {
                        new TermFilter {
                            Field = "value", Value = "asdasd"
                        }
                    }
                }),
                TrackScores  = true,
                Explain      = true,
                IndicesBoost = new Dictionary <IndexNameMarker, double>
                {
                    { Infer.Index <ElasticsearchProject>(), 2.3 }
                },
                ScriptFields = new FluentDictionary <string, IScriptFilter>()
                               .Add("script_field_name", new ScriptFilter
                {
                    Script = "doc['loc'].value * multiplier",
                    Params = new Dictionary <string, object>
                    {
                        { "multiplier", 4 }
                    }
                }),
                Sort = new List <KeyValuePair <PropertyPathMarker, ISort> >()
                {
                    new KeyValuePair <PropertyPathMarker, ISort>("field", new Sort {
                        Order = SortOrder.Ascending, Missing = "_first"
                    })
                },
                Source = new SourceFilter
                {
                    Include = new PropertyPathMarker[]
                    {
                        "na*"
                    }
                },
                Suggest = new Dictionary <string, ISuggestBucket>
                {
                    {
                        "suggestion", new SuggestBucket
                        {
                            Text       = "suggest me",
                            Completion = new CompletionSuggester
                            {
                                Analyzer  = "standard",
                                Field     = Property.Path <ElasticsearchProject>(p => p.Content),
                                Size      = 4,
                                ShardSize = 10,
                                Fuzzy     = new FuzzySuggester
                                {
                                    Fuzziness    = Fuzziness.Ratio(0.3),
                                    PrefixLength = 4
                                }
                            }
                        }
                    }
                },
                Facets = new Dictionary <PropertyPathMarker, IFacetContainer>()
                {
                    { "name", new FacetContainer
                      {
                          Terms = new TermFacetRequest
                          {
                              Field       = "field",
                              Size        = 10,
                              FacetFilter = new TermFilter()
                              {
                                  Field = "other_field",
                                  Value = "term"
                              }.ToContainer()
                          }
                      } }
                },
                Aggregations = new Dictionary <string, IAggregationContainer>
                {
                    { "my_agg", new AggregationContainer
                      {
                          Terms = new TermsAggregator
                          {
                              Field         = Property.Path <ElasticsearchProject>(p => p.Name),
                              Size          = 10,
                              ExecutionHint = TermsAggregationExecutionHint.Ordinals,
                          },
                          Aggregations = new Dictionary <string, IAggregationContainer>
                          {
                              { "max_count", new AggregationContainer()
                                                    {
                                                        Max = new MaxAggregator()
                                                        {
                                                            Field = "loc"
                                                        }
                                                    } }
                          }
                      } }
                }
            });

            var json = result.ConnectionStatus.Request.Utf8String();

            Assert.Pass(json);
        }
示例#13
0
 private Task <ICreateIndexResponse> CreateDeveloperIndexAsync() => this.Client.CreateIndexAsync(Infer.Index <Developer>(), c => c
                                                                                                 .Mappings(map => map
                                                                                                           .Map <Developer>(m => m
                                                                                                                            .AutoMap()
                                                                                                                            .Properties(DeveloperProperties)
                                                                                                                            )
                                                                                                           )
                                                                                                 );
 protected override LazyResponses ClientUsage() => Calls(
     (client, f) => client.Update(Infer.Index <Project>(), CallIsolatedValue, f),
     (client, f) => client.UpdateAsync(Infer.Index <Project>(), CallIsolatedValue, f),
     (client, r) => client.Update(r),
     (client, r) => client.UpdateAsync(r)
     );