如何在elasticsearch 7 nest 7中设置“最大\u结果\u窗口”

xvw2m8pv  于 2021-06-10  发布在  ElasticSearch
关注(0)|答案(2)|浏览(394)

默认情况下,ElasticSearch只返回10k个结果。但我需要转到最后一页,超过10公里的结果。
我做了一些尝试,通过设置“max\u result\u window”找到了一个解决方案:100000,我在kibana中执行它,在这个设置之后,甚至有5000多页可以正常工作。

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

现在,当我在源代码中创建索引时,我需要包含这个设置。但是我找不到方法来这样做。这是我的索引创建函数。如何设置“最大结果窗口”: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";
            }
        }
cidc1ykv

cidc1ykv1#

我不知道是什么原因 nest 但是在创建索引时可以很容易地完成,下面是restapi来说明这一点。
放http://localhost:9200/您的索引名/

{
    "settings": {
        "max_result_window" : 1000000 // note this
    },
    "mappings": {
        "properties": {
            "first_name": {
                "type": "text"
            },
            "last_name": {
                "type": "text"
            },
            "country": {
                "type": "text"
            },
            "state": {
                "type": "text"
            },
            "city": {
                "type": "text"
            }
        }
    }
}

在索引设置中检查其是否成功创建
得到http://localhost:9200/您的索引名/\u设置

{
    "so_1": {
        "settings": {
            "index": {
                "number_of_shards": "1",
                "provided_name": "so_1",
                "max_result_window": "1000000", // note this
                "creation_date": "1601273239277",
                "number_of_replicas": "1",
                "uuid": "eHBxaGf2TBG9GdmG5bvwkQ",
                "version": {
                    "created": "7080099"
                }
            }
        }
    }
}
gpfsuwkq

gpfsuwkq2#

您可以使用 max_result_window 使用以下代码段设置:

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

可以使用以下流畅的语法更新现有索引:

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

相关问题