Basic
Basic

Reputation: 26766

Creating an elastic index using Nest

I use elasticsearch a lot at work (from Python) but wanted to roll it into a little .Net project I'm doing in my spare time. A quick wander through NuGet brought me to Nest.

I'm defining my "model" as follows...

<ElasticType(Name:="Document")>
Public Class Document
    Property UserId As Long
    <ElasticProperty(IndexAnalyzer:="not_analyzed")>
    Property Something As String
    Property EmailAddress As String
End Class

and then attempting to create and index like this...

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

And I'm getting Failed to create index (BadRequest): MapperParsingException[mapping [Document]]; nested: MapperParsingException[Analyzer [not_analyzed] not found for field [something]];

I've tried both

<ElasticProperty(Analyzer:="not_analyzed")>

and

<ElasticProperty(IndexAnalyzer:="not_analyzed")>

What I'm trying to get it to build is json equivalent to

"something" : {"type" : "string", "index" : "not_analyzed"}

as shown in the es docs.

What am I missing?

(Elastic 0.90.6)

Upvotes: 1

Views: 1177

Answers (1)

Basic
Basic

Reputation: 26766

There was an attribute property I missed which handles this...

<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

Note the Index property which takes an Enum. Thanks to @geeky_sh for prompting me to look in the right place.

Upvotes: 3

Related Questions