I have tried to set the "not_analyzed" index type via Nest 5.5.0 and I have no idea how to do it.
My init:
var map = new CreateIndexDescriptor(INDEX_NAME)
.Mappings(ms => ms.Map<Project>(m => m.AutoMap()));
var connectionSettings = new ConnectionSettings().DefaultIndex(INDEX_NAME);
_client = new ElasticClient(connectionSettings);
_client.Index(map);
And the Project class:
[ElasticsearchType(Name = "project")]
public class Project
{
public Guid Id { get; set; }
[Text(Analyzer = "not_analyzed")]
public string OwnerIdCode { get; set; }
}
This way of init creates some kind of weird mapping after I invoke the index/_mapping REST via Postman. There is the normal "mappings" JSON section, and just below "createindexdescriptor" with almost the same data.
"examinations4": {
"mappings": {
"project": {
(...)
},
"createindexdescriptor": {
"properties": {
"mappings": {
"properties": {
"project": {
"properties": {
"properties": {
"properties": {
"id": {
"properties": {
"type": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"ownerIdCode": {
"properties": {
"analyzer": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"type": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
(...)
To set a not analyzed string field within Elasticsearch 5.0+, you should use the keyword
type, and pass the mapping either at index creation time with CreateIndex()
, or before the first document is sent to the index using Map<T>()
. In your case, I think you're looking for something like
void Main()
{
var connectionSettings = new ConnectionSettings()
.DefaultIndex("default-index");
var client = new ElasticClient(connectionSettings);
client.CreateIndex("projects", c => c
.Mappings(m => m
.Map<Project>(mm => mm
.AutoMap()
)
)
);
}
[ElasticsearchType(Name = "project")]
public class Project
{
[Keyword]
public Guid Id { get; set; }
[Keyword]
public string OwnerIdCode { get; set; }
}
I think the Id
property should also be marked as a keyword type too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With