Isanka Thalagala
Isanka Thalagala

Reputation: 1721

How to set "max_result_window" in Elasticsearch 7 NEST 7

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

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 
}

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

Upvotes: 0

Views: 4720

Answers (3)

BraveNewMath
BraveNewMath

Reputation: 8323

In kibana it looks like this

PUT index_name/_settings
{
  "max_result_window": 10000
}

Upvotes: 1

Rob
Rob

Reputation: 9979

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

Upvotes: 8

Amit
Amit

Reputation: 32376

I don't know the nest but it can be easily done while creating the index and below is the REST API to show that.

PUT HTTP://localhost:9200/your-index-name/

{
    "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"
            }
        }
    }
}

Check if its created successfully in index-settings

GET HTTP://localhost:9200/your-index-name/_settings

{
    "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"
                }
            }
        }
    }
}

Upvotes: 1

Related Questions