简体   繁体   中英

How to Index Array of String using NEST(1.8) in Elastic Search?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM