2
votes

I'm on NEST v6.3.1, ElasticSearch v6.4.2

I can't get my field to be indexed as a keyword.

I've tried both attributes:

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

and fluent:

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())
                )
            );

Both result in the same thing:

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

e.g doesn't match what i'm seeing here: https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/attribute-mapping.html

Same thing happens when i try and use [GeoPoint]. Should be type geopoint, but it's mapped to floats:

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

So i'm missing something, just not sure what.

Any help?

Thanks

1

1 Answers

1
votes

The index likely already exists, and a field mapping cannot be updated. Check .IsValid on the response from the create index call, and if invalid, take a look at the error and reason. You likely need to delete the index and create again.

Also note that multiple type mappings in one index is not allowed in Elasticsearch 6.x, and will fail. Either create separate indices for different types, or, if the types have the same field structure and you wish to index/analyze them in the same way, you may consider introducing an additional discriminator field.