我在工作中使用了弹性搜索(来自Python),但是想把它变成我在业余时间做的一个小.Net项目。通过NuGet快速漫游带我到Nest。
我正在定义我的“模型”如下......
<ElasticType(Name:="Document")>
Public Class Document
Property UserId As Long
<ElasticProperty(IndexAnalyzer:="not_analyzed")>
Property Something As String
Property EmailAddress As String
End Class
然后尝试像这样创建和索引...
Dim Ret = ES.CreateIndex(IndexName,
Function(x) x.AddMapping(Of Document)(
Function(m) m.MapFromAttributes))
If Not Ret.OK Then
With Ret.ConnectionStatus.Error
Throw New Exception(String.Format("Failed to create index ({0}): {1}", .HttpStatusCode, .ExceptionMessage))
End With
End If
我得到了Failed to create index (BadRequest): MapperParsingException[mapping [Document]]; nested: MapperParsingException[Analyzer [not_analyzed] not found for field [something]];
我试过了两次
<ElasticProperty(Analyzer:="not_analyzed")>
和
<ElasticProperty(IndexAnalyzer:="not_analyzed")>
我试图让它构建的是json相当于
"something" : {"type" : "string", "index" : "not_analyzed"}
如es docs。
所示我错过了什么?
(弹性0.90.6)
答案 0 :(得分:3)
我错过了一个处理此属性的属性属性...
<ElasticType(Name:="Document")>
Public Class Document
Property UserId As Long
<ElasticProperty(Index:=FieldIndexOption.not_analyzed)>
Property Something As String
Property EmailAddress As String
End Class
注意带有Enum的Index
属性。感谢@geeky_sh促使我在正确的位置寻找。