gpt4 book ai didi

elasticsearch - 嵌套不是自动映射未分析字段

转载 作者:行者123 更新时间:2023-12-03 01:54:35 24 4
gpt4 key购买 nike

我创建了一个映射实体:

[ElasticsearchType(Name = "cases")]
public class Case
{

[String(Name = "case_name")]
public string CaseName { get; set; }

[String(Name = "md5", Index = FieldIndexOption.NotAnalyzed)]
public string Md5 { get; set; }

}

然后:
client.Map<Case>(mp => mp.AutoMap());

但是不包括md5字段映射的索引类型:
GET _mapping
{
"myindex": {
"mappings": {
"cases": {
"properties": {
"case_name": {
"type": "string"
},
"md5": {
"type": "string"
}
}
}
}
}
}

我想念什么?

最佳答案

针对新创建的索引运行时,您的代码对我有用

void Main()
{
var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
var defaultIndex = "default-index";
var connectionSettings = new ConnectionSettings(pool)
.DefaultIndex(defaultIndex)
.PrettyJson()
.DisableDirectStreaming()
.OnRequestCompleted(response =>
{
// log out the request
if (response.RequestBodyInBytes != null)
{
Console.WriteLine(
$"{response.HttpMethod} {response.Uri} \n" +
$"{Encoding.UTF8.GetString(response.RequestBodyInBytes)}");
}
else
{
Console.WriteLine($"{response.HttpMethod} {response.Uri}");
}

Console.WriteLine();
// log out the response
if (response.ResponseBodyInBytes != null)
{
Console.WriteLine($"Status: {response.HttpStatusCode}\n\n" +
$"{Encoding.UTF8.GetString(response.ResponseBodyInBytes)}\n" +
$"{new string('-', 30)}\n");
}
else
{
Console.WriteLine($"Status: {response.HttpStatusCode}\n" +
$"{new string('-', 30)}\n");
}
});

var client = new ElasticClient(connectionSettings);

if (client.IndexExists(defaultIndex).Exists)
client.DeleteIndex(defaultIndex);

client.CreateIndex(defaultIndex);
client.Map<Case>(mp => mp.AutoMap());
client.GetMapping<Case>();
}

[ElasticsearchType(Name = "cases")]
public class Case
{
[String(Name = "case_name")]
public string CaseName { get; set; }

[String(Name = "md5", Index = FieldIndexOption.NotAnalyzed)]
public string Md5 { get; set; }
}

在控制台中产生以下内容
HEAD http://localhost:9200/default-index?pretty=true

Status: 200


------------------------------

DELETE http://localhost:9200/default-index?pretty=true

Status: 200

{
"acknowledged" : true
}

------------------------------

PUT http://localhost:9200/default-index?pretty=true
{}

Status: 200

{
"acknowledged" : true
}

------------------------------

PUT http://localhost:9200/default-index/cases/_mapping?pretty=true
{
"properties": {
"case_name": {
"type": "string"
},
"md5": {
"type": "string",
"index": "not_analyzed"
}
}
}

Status: 200

{
"acknowledged" : true
}

------------------------------

GET http://localhost:9200/default-index/_mapping/cases?pretty=true

Status: 200

{
"default-index" : {
"mappings" : {
"cases" : {
"properties" : {
"case_name" : {
"type" : "string"
},
"md5" : {
"type" : "string",
"index" : "not_analyzed"
}
}
}
}
}
}

------------------------------

关于elasticsearch - 嵌套不是自动映射未分析字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37579705/

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