gpt4 book ai didi

elasticsearch - Elasticsearch.net索引设置+分析器

转载 作者:行者123 更新时间:2023-12-03 01:55:27 31 4
gpt4 key购买 nike

我可以在C#(嵌套)中使用elasticsearch 2.3.0版本

我想将分析与索引一起使用,
但是索引设置不会改变,我也不知道为什么。
这是我的代码:

        private void button1_Click_1(object sender, EventArgs e)
{
var conn = new Uri("http://localhost:9200");
var config = new ConnectionSettings(conn);
var client = new ElasticClient(config);
string server = cmb_Serv.Text.Trim();
if (server.Length > 0)
{
string ser = server;
string uid = util.getConfigValue("SetUid");
string pwd = util.getConfigValue("SetPwd");
string dbn = cmb_Db.Text;
string tbl = cmb_Tbl.Text;
setWorkDbConnection(ser, uid, pwd, dbn);

string query = util.getConfigValue("SelectMC");
query = query.Replace("###tbl###",tbl);

using (SqlCommand cmd1 = new SqlCommand())
{
using (SqlConnection con1 = new SqlConnection())
{
con1.ConnectionString = util.WorkConnectionString;
con1.Open();
cmd1.CommandTimeout = 0; cmd1.Connection = con1;
cmd1.CommandText = query;

int id_num =0;

SqlDataReader reader = cmd1.ExecuteReader();
while (reader.Read())
{ id_num++;

Console.Write("\r" + id_num);

var mc = new mc
{
Id = id_num,
code = reader[0].ToString(),
mainclass = reader[1].ToString().Trim()
};
client.Index(mc, idx => idx.Index("mctest_ilhee"));
client.Alias(x => x.Add(a => a.Alias("mcAlias").Index("mctest_ilhee")));
client.Map<mc>(d => d
.Properties(props => props
.String(s => s
.Name(p => p.mainclass)
.Name(p2 => p2.code).Index(FieldIndexOption.Analyzed).Analyzer("whitespace"))));



} reader.Dispose();
reader.Close();

}
IndexSettings Is = new IndexSettings();
Is.Analysis.Analyzers.Add("snowball", new SnowballAnalyzer());
Is.Analysis.Analyzers.Add("whitespace", new WhitespaceAnalyzer());
}
}
}

最佳答案

首先,您的代码很奇怪。
为什么要在一段时间内进行映射?只做一次映射。
它不可能帮助您,因为您甚至没有提供错误信息。我建议添加简单的调试方法。

protected void ValidateResponse(IResponse response)
{
if (!response.IsValid ||
(response is IIndicesOperationResponse && !((IIndicesOperationResponse) response).Acknowledged))
{
var error = string.Format("Request to ES failed with error: {0} ", response.ServerError != null ? response.ServerError.Error : "Unknown");
var esRequest = string.Format("URL: {0}\n Method: {1}\n Request: {2}\n",
response.ConnectionStatus.RequestUrl,
response.ConnectionStatus.RequestMethod,
response.ConnectionStatus.Request != null
? Encoding.UTF8.GetString(response.ConnectionStatus.Request)
: string.Empty);
}
}

所有请求,例如 client.Alias client.Map 返回状态。所以你可以做
var result = client.Map<mc>(.....YOUR_CODE_HERE....)
ValidateResponse(result);

然后您将看到两件事,ES返回的正确错误+ NEST发送给ES的请求

关于elasticsearch - Elasticsearch.net索引设置+分析器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36979595/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com