我如何让关键字映射在 NEST 中工作?

How do i get Keyword mapping working in NEST?

我正在使用 NEST v6.3.1、ElasticSearch v6.4.2

我无法将我的字段作为关键字编入索引。

我已经尝试了两个属性:

[Keyword]
public string Suburb { get; set; }

并且流利:

client.CreateIndex(indexName, i => i
                .Mappings(ms => ms
                    .Map<Listing>(m => m
                        .Properties(ps => ps
                            .Keyword(k => k
                                .Name(n => n.Suburb)))
                        .AutoMap())
                    .Map<Agent>(m => m
                        .AutoMap())
                    .Map<BuildingDetails>(m => m
                        .AutoMap())
                    .Map<LandDetails>(m => m
                        .AutoMap())
                )
            );

两者的结果相同:

{
  "listings": {
    "mappings": {
      "listing": {
        "properties": {          
          "suburb": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
      }
    }
  }
}

例如,与我在这里看到的不符: https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/attribute-mapping.html

当我尝试使用 [GeoPoint] 时,同样的事情发生了。应该是地理点类型,但它映射到浮点数:

"latLong": {
            "properties": {
              "lat": {
                "type": "float"
              },
              "lon": {
                "type": "float"
              }
            }
          }

所以我错过了一些东西,只是不确定是什么。

有什么帮助吗?

谢谢

索引可能已经存在,无法更新字段映射。检查 create index 调用的响应 .IsValid,如果无效,请查看错误和原因。您可能需要删除索引并重新创建。

另请注意,Elasticsearch 6.x 不允许在一个索引中进行多种类型映射,否则会失败。为不同的类型创建单独的索引,或者,如果类型具有相同的字段结构 您希望以相同的方式 index/analyze 它们,您可以考虑引入额外的鉴别器场.