微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么在创建索引后它会显示旧索引中的数据?

如何解决为什么在创建索引后它会显示旧索引中的数据?

我正在使用它在使用 asp.net mvc 的弹性搜索中使用嵌套 api 创建索引。

它可以工作,但每次我运行它时,它都会填充并显示上次运行的数据,而不是新的数据。

我什至在开始时删除索引。

我在申请开始时调用它。

 public static void CreateIndex()
        {
            ConnectionSettings settings = new ConnectionSettings(new Uri("http://localhost:9200"));
            settings.DefaultIndex("employeestore");
            Elasticclient client = new Elasticclient(settings);
            client.Indices.Delete(Indices.Index("employeestore"));
            var indexSettings = client.Indices.Exists("employeestore");
            if (!indexSettings.Exists)
            {
                var response = client.Indices.Create(Indices.Index("employeestore"));
            }

        }

        public static void CreateSeed()
        {
            int seedValue = 1;
            int limitValue = 20000;

            IList<News> NewsList = new List<News>();

            ConnectionSettings settings = new ConnectionSettings(new Uri("http://localhost:9200"));
            settings.DefaultIndex("employeestore");
            Elasticclient esClient = new Elasticclient(settings);
            while (seedValue <= limitValue)
            {
                var news = new News() { NewsID = seedValue,NewsTitle = "News" + seedValue.ToString(),IsPublished = true };
                var response = esClient.IndexAsync(news,idx => idx.Index("employeestore"));
                seedValue++;
            }

        }
        /// <summary>  
        ///   
        /// </summary>  
        public static void CreateMappings()
        {
            ConnectionSettings settings = new ConnectionSettings(new Uri("http://localhost:9200"));
            settings.DefaultIndex("employeestore");
            Elasticclient esClient = new Elasticclient(settings);
            esClient.Map<News>(m =>
            {
                var putMappingDescriptor = m.Index(Indices.Index("employeestore")).AutoMap();
                return putMappingDescriptor;
            });
        }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。