3

I want to Index Array of String in Elastic Search Using NEST(1.8) C#.

Here is my Mapping

using Nest;
using System;
using System.Data;

namespace ElasticSearch_Final
{
    //[ElasticType(IdProperty = "Id", Name = "indexMapping")]
    public class indexMapping
    {
        [ElasticProperty(Name = "Field1", Index = FieldIndexOption.NotAnalyzed, Type = FieldType.String, Store = true)]
        public Guid? Field1 { get; set; }

        [ElasticProperty(Name = "Field2", Index = FieldIndexOption.NotAnalyzed, Type = FieldType.String, Store = true)]
        public string Field2 { get; set; }

        [ElasticProperty(Name = "Field3", Index = FieldIndexOption.NotAnalyzed, Type = FieldType.String, Store = true)]
        public string Field3 { get; set; }

        [ElasticProperty(Name = "Field4", Index = FieldIndexOption.NotAnalyzed, Type = FieldType.String, Store = true)]
        public string Field1 { get; set; }

        [ElasticProperty(Name = "Field4", Index = FieldIndexOption.NotAnalyzed, Type = FieldType.String, Store = true)]
        public string Field1 { get; set; }

        [ElasticProperty(Name = "Data", Index = FieldIndexOption.Analyzed, Type = FieldType.String, Store = false)]
        public string[] Data { get; set; }

    }
}

I want this field to be Indexed as String Array.

 [ElasticProperty(Name = "Data", Index = FieldIndexOption.Analyzed, Type = FieldType.String, Store = false)]
            public string[] Data { get; set; }

But there is No Field type like Array in ElasticProperty!

So, Which FieldType I should use or Any other options to Index String Array Data?

1 Answer 1

3

I'm going to link you to the elastic documentation for this. array datatype

A field in Elastic can contain zero, one or more values by default, no need to specify an array. Only requirement is that all the data in the array is of the same type.

So to index an array, specify Data as string in Elastic, and just pass an array of string when indexing. Elastic will index it as a JSON array.

Judging by the code you posted, that should work to index an array of strings on Data.

Sign up to request clarification or add additional context in comments.

2 Comments

Ok! Got it! Thank you so much!
would it be reasonable to say the c# models of class Bar { string Foo {get;set;} } and the model of class Bar { string[] Foo {get;set;} } at the elasticsearch level are indistinguishable?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.