What I would like to do is to store multiple languages under one index field. I understand I need structure as explained here.
Here is sample class with multi-filed property "Name":
public class Data
{
public int ID { get; set; }
public string Name { get; set; }
}
Index mapping:
ElasticsearchConfiguration.Instance.Client.CreateIndex("data", i =>
i.Settings(s =>
s.NumberOfShards(2)
.NumberOfReplicas(0))
.Mappings(m =>
m.Map<Data>(map =>
map.AutoMap()
.Properties(ps => ps
.Text(s => s
.Name(n => n.Name)
.Fields(f => f
.Text(st => st
.Name("en")
.Analyzer("english"))
.Text(st => st
.Name("de")
.Analyzer("german"))))))));
Mapping "object type -> index name" is done on the creation of the ElasticClient. This is how I send data to the elasticsearch server:
var dataPartitions = DBUtil.GetData().Partition(1000);
foreach (var partition in dataPartitions)
{
var result = ElasticsearchConfiguration.Instance.Client.Bulk(b => b.IndexMany(partition));
if (!result.IsValid)
{
Environment.Exit(1);
}
}
So, I have configured index as I wanted, but I don't know how to include separate values for German and English sub properties while indices are creating. Do I must have nested class instead "Name" with hard-coded properties for each language (in this case "en", and "de")? Or, maybe send separate request for the language properties?