【问题标题】:Elasticsearch NEST V2 Completion Context MappingElasticsearch NEST V2 完成上下文映射
【发布时间】:2016-05-18 08:02:44
【问题描述】:

我具有提供自动完成功能所需的功能,该功能仅在我的索引中返回某种类型的文档。

我有自动完成建议器在没有应用上下文的情况下工作。但是当我尝试映射上下文时,它失败了。

这是我的映射。

.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" })
            )
        )
    )
)

不确定我做错了什么,因为在智能感知或构建中没有任何错误。

【问题讨论】:

  • 什么版本的 NEST 2.x?您使用的是哪个版本的 Elasticsearch?
  • NEST 2.1.0 和 Elasticsearch 2.3.0

标签: elasticsearch autocomplete nest


【解决方案1】:

The Context Suggester mapping 不正确,不会按原样编译; AutoMap() 不是PropertiesDescriptor&lt;T&gt; 上的方法,而是PutMappingDescriptor&lt;T&gt; 上的方法。看看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"
          ]
        }
      }
    }
  }
}

【讨论】:

猜你喜欢
  • 2020-01-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-14
  • 2015-03-29
  • 2015-12-01
相关资源
最近更新 更多