Ejemplo n.º 1
0
        public void CreateNewIndexAndMappingWithAnalyzer()
        {
            var indexDefinition = new IndexDefinition { IndexSettings = { NumberOfShards = 3, NumberOfReplicas = 1 } };
            indexDefinition.Mapping.All.Enabled = false;
            indexDefinition.Mapping.Analyzer = new MappingAnalyzer { Path = "myanalyzer" };

            var mappingTypeAll = new MappingTypeAnalyzerTest
            {
                Id = 1,
                SomeText = "I think search engines are great",
                MyAnalyzer= "whitespace"

            };

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

                context.AddUpdateDocument(mappingTypeAll, mappingTypeAll.Id);
                context.SaveChanges();

                Thread.Sleep(1500);

                var doc = context.Search<MappingTypeAnalyzerTest>(BuildSearchById(1));
                Assert.GreaterOrEqual(doc.PayloadResult.Hits.HitsResult.First().Id.ToString(), "1");
            }
        }
Ejemplo n.º 2
0
        public void CreateNewIndexAndMappingWithSourceDisabled()
        {
            var indexDefinition = new IndexDefinition {IndexSettings = {NumberOfShards = 3, NumberOfReplicas = 1}};
            indexDefinition.Mapping.Source.Enabled = false;

            var mappingTypeAll = new MappingTypeSourceTest
            {
                Id = 1,
                DescStoreFalse = "non",
                DescStoreTrue = "yes",
                DescThreeNoDef = "three"
            };

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

                context.AddUpdateDocument(mappingTypeAll, mappingTypeAll.Id);
                context.SaveChanges();

                Thread.Sleep(1500);

                var doc = context.Search<MappingTypeSourceTest>(BuildSearchById(1));
                Assert.GreaterOrEqual(doc.PayloadResult.Hits.HitsResult.First().Id.ToString(), "1");
                Assert.IsNull(doc.PayloadResult.Hits.HitsResult.First().Source);
            }
        }
Ejemplo n.º 3
0
        public void CreateNewIndexAndMappingWithSimpleNullListAndNullArrayListAndAliasAnd2Warmers()
        {
            var indexDefinition = new IndexDefinition
            {
                IndexAliases = new IndexAliases
                {
                    Aliases = new List<IndexAlias>
                    {
                        new IndexAlias("testnew"),
                        new IndexAlias("testnewroute")
                        {
                            Routing = "ddd"
                        }
                    }
                },
                IndexWarmers = new IndexWarmers
                {
                    Warmers = new List<IndexWarmer>
                    {
                        new IndexWarmer("warmer_one")
                        {
                            Query = new Query(new MatchAllQuery()),
                            Aggs = new List<IAggs>
                            {
                                new SumMetricAggregation("sum", "id")
                            }
                        },
                        new IndexWarmer("warmer_two")
                        {
                            Query = new Query(new MatchAllQuery()),
                            IndexTypes = new List<string>
                            {
                                "dd",
                                "ee"
                            }
                        }
                    }
                }
            };

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

                Thread.Sleep(1500);
                var result = context.IndexExists<AliasCreateIndexOne>();
                Assert.IsTrue(result);
            }
        }