Elasticsearch 2.3.1 Nest client Raw String Update

When upgrading to elastic 2.3.1, I encountered a problem with the .Net Nest client.

In Nest 1.0, I could read the index settings from a file and configure the index when creating using the original string. Is there a way to do something like this in Nest 2.0, or do I need to use a free API for each setup, including part of the analysis? The same question for mappings.

Nest 1.0

private bool CreateIndex(string index, FileInfo settingsFile)
{
    var settings = File.ReadAllText(settingsFile.FullName);

    IElasticsearchConnector _elastic
    var response = _elastic.Client.Raw.IndicesCreate(index, settings);

    if (!response.IsValid)
    {
        //Logging error
        return false
    }
    return true;
}
+4
source share
1 answer

ElasticClient.Rawwas renamed to ElasticClient.LowLevel.

Here is how you can compose your request in NEST 2.x.

_elastic.Client.LowLevel.IndicesCreate<object>(indexName, File.ReadAllText("index.json"));

File contents index.json:

{
    "settings" : {
        "index" : {
            "number_of_shards" : 1,
            "number_of_replicas" : 1
        },
        "analysis" : {
            "analyzer" : {
                "analyzer-name" : {
                    "type" : "custom",
                    "tokenizer" : "keyword",
                    "filter" : "lowercase"
                }
            }
        },
        "mappings" : {
            "employeeinfo" : {
                "properties" : {
                    "age" : {
                        "type" : "long"
                    },
                    "experienceInYears" : {
                        "type" : "long"
                    },
                    "name" : {
                        "type" : "string",
                        "analyzer" : "analyzer-name"
                    }
                }
            }
        }
    }
}

Hope this helps.

+5
source

All Articles