当前位置: 首页>>代码示例>>C#>>正文


C# ElasticsearchContext类代码示例

本文整理汇总了C#中ElasticsearchContext的典型用法代码示例。如果您正苦于以下问题:C# ElasticsearchContext类的具体用法?C# ElasticsearchContext怎么用?C# ElasticsearchContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ElasticsearchContext类属于命名空间,在下文中一共展示了ElasticsearchContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SearchQueryBoolQuery

        public void SearchQueryBoolQuery()
        {
            var search = new Search
            {
                Query = new Query(
                    new BoolQuery
                    {
                        Must = new List<IQuery>
                        {
                            new RangeQuery("id") { GreaterThanOrEqualTo = "2", LessThan = "3", LessThanOrEqualTo = "2", GreaterThan = "1" }
                        },
                        MustNot = new List<IQuery>
                        {
                            new RangeQuery("id") {GreaterThan="34"}
                        },
                        Should = new List<IQuery>
                        {
                            new TermQuery("name", "two")
                        },
                        Boost=2.0,
                        DisableCoord= false,
                        MinimumShouldMatch= "2"
                    }
                )
            };

            using (var context = new ElasticsearchContext(ConnectionString, ElasticsearchMappingResolver))
            {
                context.TraceProvider = new ConsoleTraceProvider();
                Assert.IsTrue(context.IndexTypeExists<SearchTest>());
                var items = context.Search<SearchTest>(search);
                Assert.AreEqual(2, items.PayloadResult.Hits.HitsResult[0].Source.Id);
            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:34,代码来源:SearchQueryQueryTests.cs

示例2: SearchAggTermsBucketAggregationnWithChildrenSubAggNoHits

        public void SearchAggTermsBucketAggregationnWithChildrenSubAggNoHits()
        {
            var search = new Search
            {
                Aggs = new List<IAggs>
                {
                    new TermsBucketAggregation("test_min", "info")
                    {
                        Aggs = new List<IAggs>
                        {
                            new ChidrenBucketAggregation("childrenAgg", "testobjchildsep")
                            {
                                Aggs = new List<IAggs>
                                {
                                    new TermsBucketAggregation("infoAgg", "info")
                                }
                            }
                        }
                    }
                }
            };

            using (var context = new ElasticsearchContext(ConnectionString, ElasticsearchMappingResolver))
            {
                Assert.IsTrue(context.IndexTypeExists<TestObjParentSep>());
                Assert.IsTrue(context.IndexTypeExists<TestObjChildSep>());

                var items = context.Search<TestObjParentSep>(search, new SearchUrlParameters { SeachType = SeachType.count });
                var aggResult = items.PayloadResult.Aggregations.GetComplexValue<TermsBucketAggregationsResult>("test_min");

                Assert.AreEqual(3, aggResult.Buckets[0].DocCount);

            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:34,代码来源:SearchQueryQueryTopChildrenAndChidrenBucketAggregationTests.cs

示例3: CreateAliasForIndex2

        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"));

            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:26,代码来源:AliasElasticsearchCrudTests.cs

示例4: SearchAggGeohashGridBucketAggregationWithTopHitsSubWithNoHits

        public void SearchAggGeohashGridBucketAggregationWithTopHitsSubWithNoHits()
        {
            var search = new Search
            {
                Aggs = new List<IAggs>
                {
                    new GeohashGridBucketAggregation("testGeohashGridBucketAggregation", "location")
                    {
                        Aggs = new List<IAggs>
                        {
                            new TopHitsMetricAggregation("tophits")
                        }
                    }
                }
            };

            using (var context = new ElasticsearchContext(ConnectionString, ElasticsearchMappingResolver))
            {
                Assert.IsTrue(context.IndexTypeExists<SearchAggTest>());
                var items = context.Search<SearchAggTest>(search, new SearchUrlParameters { SeachType = SeachType.count });
                var aggResult = items.PayloadResult.Aggregations.GetComplexValue<GeohashGridBucketAggregationsResult>("testGeohashGridBucketAggregation");
                var topHits = aggResult.Buckets[0].GetSubAggregationsFromJTokenName<TopHitsMetricAggregationsResult<SearchAggTest>>("tophits");
                Assert.AreEqual(3, aggResult.Buckets[0].DocCount);
                Assert.AreEqual(3, topHits.Hits.Total);
            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:26,代码来源:GeohashGridBucketAggregationTests.cs

示例5: SearchQueryMoreLikeThisQuery

        public void SearchQueryMoreLikeThisQuery()
        {
            var search = new Search
            {
                Query = new Query(
                    new MoreLikeThisQuery
                    {
                        Fields = new List<string> {"moreinfo"},
                        LikeText = "yes one",
                        MinTermFreq = 1,
                        Boost = 50,
                        MinDocFreq = 1,
                        PercentTermsToMatch = 0.01

                    }
                )
            };

            using (var context = new ElasticsearchContext(ConnectionString, ElasticsearchMappingResolver))
            {
                context.TraceProvider = new ConsoleTraceProvider();
                Assert.IsTrue(context.IndexTypeExists<MoreLikeThisTestDto>());
                var items = context.Search<MoreLikeThisTestDto>(search);
                Assert.AreEqual(2, items.PayloadResult.Hits.Total);
            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:26,代码来源:SearchQueryFilterTestsMoreLikeThis.cs

示例6: SearchAggFilterBucketAggregationWithChildrenNoHits

        public void SearchAggFilterBucketAggregationWithChildrenNoHits()
        {
            var search = new Search
            {
                Aggs = new List<IAggs>
                {
                    new FilterBucketAggregation("globalbucket", new GeoDistanceFilter("location", new GeoPoint(32,42), new DistanceUnitKilometer(10000) ))
                    {
                        Aggs = new List<IAggs>
                        {
                            new MaxMetricAggregation("maxAgg", "lift"),
                            new MinMetricAggregation("minAgg", "lift"),
                            new TopHitsMetricAggregation("topHits")
                            {
                                Size = 3
                            }
                        }
                    }
                }
            };

            using (var context = new ElasticsearchContext(ConnectionString, ElasticsearchMappingResolver))
            {
                Assert.IsTrue(context.IndexTypeExists<SearchAggTest>());
                var items = context.Search<SearchAggTest>(search, new SearchUrlParameters { SeachType = SeachType.count });
                var aggResult = items.PayloadResult.Aggregations.GetComplexValue<GlobalBucketAggregationsResult>("globalbucket");
                var max = aggResult.GetSingleMetricSubAggregationValue<double>("maxAgg");
                Assert.AreEqual(7, aggResult.DocCount);
                Assert.AreEqual(2.9, max);
            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:31,代码来源:FilterBucketAggregationAndMissingBucketAggregationTests.cs

示例7: CreateNewIndexAndMappingWithSimpleNullListAndNullArrayListAndAlias

        public void CreateNewIndexAndMappingWithSimpleNullListAndNullArrayListAndAlias()
        {
            using (var context = new ElasticsearchContext(ConnectionString, new ElasticsearchSerializerConfiguration(_elasticsearchMappingResolver)))
            {
                context.TraceProvider = new ConsoleTraceProvider();
                context.IndexCreate<AliasCreateIndexOne>(
                    new IndexDefinition
                    {
                        IndexAliases = new IndexAliases
                        {
                            Aliases = new List<IndexAlias>
                            {
                                new IndexAlias("testnew"), new IndexAlias("testnewroute")
                                {
                                    Routing = "ddd"
                                }
                            }
                        }
                    });

                Thread.Sleep(1500);
                var result = context.IndexExists<AliasCreateIndexOne>();
                Assert.IsTrue(result);
            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:25,代码来源:CreateIndexTest.cs

示例8: SearchAggScriptedMetricAggregationWithParamsWithNoHits

        public void SearchAggScriptedMetricAggregationWithParamsWithNoHits()
        {
            var search = new Search
            {
                Aggs = new List<IAggs>
                {
                    new ScriptedMetricAggregation("topScriptedMetricAggregation", "_agg.transactions.add(doc['lift'].value  * _agg.times)")
                    {
                        InitScript= "_agg['transactions'] = []",
                        CombineScript= "script_calculated = 0; for (t in _agg.transactions) { script_calculated += t }; return script_calculated",
                        ReduceScript= "script_calculated = 0; for (a in _aggs) { script_calculated += a }; return script_calculated",
                        Params = new ParamsForScript("_agg")
                        {
                            Params = new List<ScriptParameter>
                            {
                                new ScriptParameter("times", 1.4),
                            }
                        }
                    }
                }
            };

            using (var context = new ElasticsearchContext(ConnectionString, ElasticsearchMappingResolver))
            {
                Assert.IsTrue(context.IndexTypeExists<SearchAggTest>());
                var items = context.Search<SearchAggTest>(search, new SearchUrlParameters { SeachType = SeachType.count });
                var aggResult = items.PayloadResult.Aggregations.GetSingleMetricAggregationValue<double>("topScriptedMetricAggregation");
                Assert.AreEqual(22.82, aggResult);

            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:31,代码来源:ScriptedMetricAggregationTests.cs

示例9: SearchAggDateRangesBucketAggregationKeyedWithNoHits

        public void SearchAggDateRangesBucketAggregationKeyedWithNoHits()
        {
            var search = new Search
            {
                Aggs = new List<IAggs>
                {
                    new DateRangeBucketAggregation("testRangesBucketAggregation", "dateofdetails", "MM-yyy", new List<RangeAggregationParameter<string>>
                    {
                        new ToRangeAggregationParameter<string>("now-8M/M"),
                        new ToFromRangeAggregationParameter<string>("now-8M/M", "now-10M/M"),
                        new FromRangeAggregationParameter<string>("now-10M/M")
                        {
                            Key = "keyName"
                        }
                    })
                    {
                        Keyed= true
                    }
                }
            };

            using (var context = new ElasticsearchContext(ConnectionString, ElasticsearchMappingResolver))
            {
                Assert.IsTrue(context.IndexTypeExists<SearchAggTest>());
                var items = context.Search<SearchAggTest>(search, new SearchUrlParameters { SeachType = SeachType.count });
                var aggResult = items.PayloadResult.Aggregations.GetComplexValue<RangesNamedBucketAggregationsResult>("testRangesBucketAggregation");
                var test = aggResult.Buckets.GetSubAggregationsFromJTokenName<RangeBucket>("keyName");

                Assert.AreEqual(7, test.DocCount);
            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:31,代码来源:RangesAggregationTests.cs

示例10: SearchAggSignificantTermsBucketAggregationPropertiesSet

        public void SearchAggSignificantTermsBucketAggregationPropertiesSet()
        {
            var search = new Search
            {
                Query = new Query(new MatchAllQuery()),
                Aggs = new List<IAggs>
                {
                    new SignificantTermsBucketAggregation("testSignificantTermsBucketAggregation", "details")
                    {
                        BackgroundFilter= new TermFilter("name", "details"),
                        InformationRetrievalRetrieval = new MutualInformation
                        {
                            BackgroundIsSuperset = false,
                            IncludeNegatives = false
                        },
                        ExecutionHint= ExecutionHint.global_ordinals
                    }
                }
            };

            using (var context = new ElasticsearchContext(ConnectionString, ElasticsearchMappingResolver))
            {
                Assert.IsTrue(context.IndexTypeExists<SearchAggTest>());
                var items = context.Search<SearchAggTest>(search, new SearchUrlParameters { SeachType = SeachType.count });
                var aggResult = items.PayloadResult.Aggregations.GetComplexValue<SignificantTermsBucketAggregationsResult>("testSignificantTermsBucketAggregation");
                Assert.AreEqual(7, aggResult.DocCount);
            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:28,代码来源:SignificantTermsBucketAggregationTests.cs

示例11: SearchAggGeohashGridBucketAggregationWithSubAggSignificantTermsBucketAggregationWithNoHits

        public void SearchAggGeohashGridBucketAggregationWithSubAggSignificantTermsBucketAggregationWithNoHits()
        {
            var search = new Search
            {
                Aggs = new List<IAggs>
                {
                    new GeohashGridBucketAggregation("termsDetails", "location")
                    {
                        Aggs = new List<IAggs>
                        {
                            new SignificantTermsBucketAggregation("testSignificantTermsBucketAggregation", "details")
                        },
                        Precision = 2
                    }
                }
            };

            using (var context = new ElasticsearchContext(ConnectionString, ElasticsearchMappingResolver))
            {
                Assert.IsTrue(context.IndexTypeExists<SearchAggTest>());
                var items = context.Search<SearchAggTest>(search, new SearchUrlParameters { SeachType = SeachType.count });
                var termsAggResult = items.PayloadResult.Aggregations.GetComplexValue<TermsBucketAggregationsResult>("termsDetails");
                var significantAggResult = termsAggResult.Buckets[0].GetSubAggregationsFromJTokenName<SignificantTermsBucketAggregationsResult>("testSignificantTermsBucketAggregation");
                Assert.AreEqual(3, significantAggResult.Buckets[0].BgCount);
            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:26,代码来源:SignificantTermsBucketAggregationTests.cs

示例12: CreateGeoShapeCircleMapping

        public void CreateGeoShapeCircleMapping()
        {
            var geoShapeCircleDto = new GeoShapeCircleDto
            {
                CircleTest = new GeoShapeCircle
                {
                    Coordinates = new GeoPoint(45, 45),
                    Radius="100m"
                },
                Id = "1",
                Name = "test",
            };

            using (var context = new ElasticsearchContext(ConnectionString, new ElasticsearchSerializerConfiguration(_elasticsearchMappingResolver)))
            {
                context.TraceProvider = new ConsoleTraceProvider();
                context.IndexCreate<GeoShapeCircleDto>();

                Thread.Sleep(1500);
                Assert.IsNotNull(context.IndexExists<GeoShapeCircleDto>());

                context.AddUpdateDocument(geoShapeCircleDto, geoShapeCircleDto.Id);
                context.SaveChanges();
                Thread.Sleep(1500);
                Assert.AreEqual(1, context.Count<GeoShapeCircleDto>());
                var result = context.SearchById<GeoShapeCircleDto>(1);
                Assert.AreEqual(geoShapeCircleDto.CircleTest.Coordinates.Count, result.CircleTest.Coordinates.Count);
            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:29,代码来源:GeoPointAndGeoShapeTests.cs

示例13: SearchQueryQueryStringQueryAllProperties

        public void SearchQueryQueryStringQueryAllProperties()
        {
            var search = new Search
            {
                Query = new Query(new QueryStringQuery("one document")
                {
                    AllowLeadingWildcard = true,
                    Analyzer = LanguageAnalyzers.German,
                    AnalyzeWildcard = false,
                    AutoGeneratePhraseQueries = false,
                    Boost = 2.1,
                    DefaultField = "_all",
                    DefaultOperator = QueryDefaultOperator.OR,
                    EnablePositionIncrements = true,
                    Fuzziness = 0.5,
                    FuzzyMaxExpansions = 49,
                    FuzzyPrefixLength = 0,
                    Lenient = false,
                    Locale = "ROOT"
                })
            };

            using (var context = new ElasticsearchContext(ConnectionString, ElasticsearchMappingResolver))
            {
                Assert.IsTrue(context.IndexTypeExists<SearchTest>());
                var items = context.Search<SearchTest>(search);
                Assert.AreEqual(2, items.PayloadResult.Hits.Total);
            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:29,代码来源:SearchQueryQueryStringQueryTest.cs

示例14: SearchAggTermsBucketAggregationWithSubTopHitsMetricAggregationWithNoHits

        public void SearchAggTermsBucketAggregationWithSubTopHitsMetricAggregationWithNoHits()
        {
            var search = new Search
            {
                Aggs = new List<IAggs>
                {
                    new TermsBucketAggregation("test_min", "lift")
                    {
                        Aggs = new List<IAggs>
                        {
                            new TopHitsMetricAggregation("topHits")
                            {
                                Size = 5
                            }
                        }
                    }
                }
            };

            using (var context = new ElasticsearchContext(ConnectionString, ElasticsearchMappingResolver))
            {
                Assert.IsTrue(context.IndexTypeExists<SearchAggTest>());
                var items = context.Search<SearchAggTest>(search, new SearchUrlParameters { SeachType = SeachType.count });
                var aggResult = items.PayloadResult.Aggregations.GetComplexValue<TermsBucketAggregationsResult>("test_min");
                var hitsForBucket = aggResult.Buckets[0].GetSubAggregationsFromJTokenName<TopHitsMetricAggregationsResult<SearchAggTest>>("topHits");

                Assert.AreEqual(3, aggResult.Buckets[0].DocCount);
                Assert.AreEqual(2.1, hitsForBucket.Hits.HitsResult[0].Source.Lift);
            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:30,代码来源:TopHitsAggregationTests.cs

示例15: CloseIndexWhichDoesNotExist

 public void CloseIndexWhichDoesNotExist()
 {
     using (var context = new ElasticsearchContext(ConnectionString, new ElasticsearchSerializerConfiguration(_elasticsearchMappingResolver)))
     {
         context.IndexClose("help");
     }
 }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:7,代码来源:MappingTests.cs


注:本文中的ElasticsearchContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。