如何设置“max_result_window"在 Elasticsearch 7 NEST 7 [英] How to set "max_result_window" in Elasticsearch 7 NEST 7

查看:449
本文介绍了如何设置“max_result_window"在 Elasticsearch 7 NEST 7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认弹性搜索只返回 10k 结果.但是我需要转到超过10k结果的最后一页.

In default elastic search only returns 10k results. But I need to go to the last page which exceeds 10k results.

我做了一些尝试并通过设置max_result_window"找到了解决方案.: 100000我在 Kibana 中执行它,在此设置后,甚至超过 5000 页都可以正常工作.

I did some reach and found a solution by setting "max_result_window" : 100000 And I execute it in Kibana and even more thanx 5000pages works fine after this setting.

PUT jm-stage-products/_settings
{ 
  "max_result_window" : 100000 
}

现在我需要在我的源代码中创建索引时包含这个设置.但我找不到办法做到这一点.这是我的索引创建函数.我应该如何设置max_result_window"?:100000?

Now I need to include this setting when I'm creating an index in my source code.But I coundn't find a way to do it. This is my index create function. How should I set "max_result_window" : 100000?

  public string InitIndexing()
        {
            var indexName = string.Format(_config.ElasticIndexName, _config.HostingEnvironment);

            //-----------------------------------------------------------
            if (!_client.Indices.Exists(indexName).Exists)
            {
                //----------------------------------------------
                var indexSettings = new IndexSettings
                {
                    NumberOfReplicas = 0, // If this is set to 1 or more, then the index becomes yellow.
                    NumberOfShards = 5,                  
                };
             
                var indexConfig = new IndexState
                {
                    Settings = indexSettings
                };
                var createIndexResponses = _client.Indices.Create(indexName, c => c
                                          .InitializeUsing(indexConfig)                      
                                         .Map<ElasticIndexGroupProduct>(m => m.AutoMap())
               );
                return createIndexResponses.DebugInformation;
            }
            else
            {
                return $"{_config.ElasticIndexName} already exists";
            }
        }

推荐答案

您可以使用 max_result_window 设置创建索引,代码片段如下:

You can create an index with max_result_window setting with following code snippet:

var createIndexResponse = await elasticClient.Indices.CreateAsync("index_name", c => c
    .Settings(s => s
        .Setting(UpdatableIndexSettings.MaxResultWindow, 100000)))

可以使用这种流畅的语法更新已经存在的索引:

Already existing index can be updated with this fluent syntax:

await elasticClient.Indices.UpdateSettingsAsync("index_name", s => s
    .IndexSettings(i => i.Setting(UpdatableIndexSettings.MaxResultWindow, 100000)));

这篇关于如何设置“max_result_window"在 Elasticsearch 7 NEST 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆