그림과 같이 문자열 값 배열이있는 그룹 필드가 있습니다. 그러나 List<string>
속성에 매핑하려고 할 때 예외가 발생합니다.Elasticsearch를 사용하여 배열 필드를 C# 문자열 목록에 매핑
뭔가
Error converting value \"[134706634,134706635]\" to type System.Collections.Generic.IList[System.String]'
처럼 나는 아무도 일하지 제외한 elasticsearch가 제공하는 몇 가지의 다양한 속성을 사용했습니다. json 변환기 속성은 제대로 작동하지만 원하는 방식으로 작동하도록 많은 코드를 작성해야합니다.
NEST에서 더 명확하고 자연스러운 방법이 있습니까?
C# 코드 :
var groupQuery = await
elastic.SearchAsync<CorrelationGroup>(s => s
.Query(q => q
.Bool(b => b
.Must(
m => m.ConstantScore(c => c
.Filter(f => f
.Term(x => x.Type, counterType))
),
m => m.ConstantScore(c => c.
Filter(f => f
.Term(x => x.TypeValue, counterTypeValue))))))
.Index("correlation-groups").AllTypes());
public class CorrelationGroup
{
[Text(Name = "type")]
public string Type { get; set; }
[Text(Name = "type_value")]
public string TypeValue { get; set; }
public List<string> Groups { get; set; }
}
소스 JSON 파일 :
[ { "type": "APN", "type_value": "internet", "groups": [150994936,150994940] }, { "type": "APN", "type_value": "internet", "groups": [150984921,150984922] }, { "type": "APN", "type_value": "internet", "groups": [150984917,150984918,150984921,150984922] } ]
내 템플릿은 다음과 같습니다
{
"template": "correlation-groups",
"settings" : {
"number_of_shards" : 2,
"number_of_replicas" : 0,
"index" : {
"store" : { "compress" : { "stored" : true, "tv": true } }
}
},
"dynamic_templates": [
{
"string_template" : {
"match" : "*",
"mapping": { "type": "string", "index": "not_analyzed" },
"match_mapping_type" : "string"
}
}
],
"mappings": {
"_default_": {
"properties": {
"type": { "type": "string", "index": "not_analyzed" },
"type_value": { "type": "string", "index": "not_analyzed" },
"groups": { "type": "string"}
}
}
}
}
배열이 실제로 문자열 인 것 같습니다. 배열'\ "[134706634,134706635] \"주위의 이스케이프 된 이중 따옴표를 참조하십시오. 'groups' 배열이 어떤 시점에서 문자열 화되어 문자열로 저장되었을 가능성이 큽니다. – Val
인덱스 매핑을 어떻게 만들고 인덱스 데이터를 어떻게 작성하는지 확인하는 것이 좋습니다. – Rob
@Val 템플릿에서 타입 문자열을 지정했습니다. (내가 문서에서 이해 한 것) 대신 다른 것을 사용해야합니까? – Cemre