2016-05-12 92 views
0

我有提供自動完成所需的功能,該自動完成只返回索引中特定類型的文檔。Elasticsearch NEST V2完成上下文映射

我有沒有應用上下文的自動完成建議者工作。但是當我嘗試映射上下文時,它失敗了。

這是我有的映射。

.Map<MyType>(l => l 
.Properties(p => p 
    .Boolean(b => b 
     .Name(n => n.IsArchived) 
    ) 
    .String(s => s 
     .Name(n => n.Type) 
     .Index(FieldIndexOption.No) 
    ) 
    .AutoMap() 
    .Completion(c => c 
     .Name(n => n.Suggest) 
     .Payloads(false) 
     .Context(context => context 
      .Category("type", cat => cat 
       .Field(field => field.Type) 
       .Default(new string[] { "defaultType" }) 
      ) 
     ) 
    ) 
) 

不知道我在做什麼錯,因爲在intellisense或build中沒有任何錯誤。

+0

NEST 2.X的是什麼版本?你碰到什麼版本的Elasticsearch? –

+0

NEST 2.1.0和Elasticsearch 2.3.0 –

+0

@RussCam ?????? –

回答

1

The Context Suggester mapping是不正確的,不會按原樣編譯; AutoMap()不是PropertiesDescriptor<T>上的方法,而是PutMappingDescriptor<T>上的方法。看看the completion suggester mapping that is used as part of the integration tests。它應該看起來像下面

public class MyType 
{ 
    public bool IsArchived { get; set;} 

    public string Type { get; set;} 

    public CompletionField<object> Suggest { get; set;} 
} 

client.Map<MyType>(l => l 
    .AutoMap() 
    .Properties(p => p 
     .Boolean(b => b 
      .Name(n => n.IsArchived) 
     ) 
     .String(s => s 
      .Name(n => n.Type) 
      .Index(FieldIndexOption.No) 
     ) 

     .Completion(c => c 
      .Name(n => n.Suggest) 
      .Context(context => context 
       .Category("type", cat => cat 
        .Field(field => field.Type) 
        .Default("defaultType") 
       ) 
      ) 
     ) 
    ) 
); 

導致下面的映射

{ 
    "properties": { 
    "isArchived": { 
     "type": "boolean" 
    }, 
    "type": { 
     "type": "string", 
     "index": "no" 
    }, 
    "suggest": { 
     "type": "completion", 
     "context": { 
     "type": { 
      "type": "category", 
      "path": "type", 
      "default": [ 
      "defaultType" 
      ] 
     } 
     } 
    } 
    } 
} 
+0

乾杯。在我的例子中,我沒有提到我試圖用多種類型進行映射。我試圖爲每種類型設置不同的默認值,這是它失敗的地方。 https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html#field-conflicts –