簡體   English   中英

如何在彈性搜索中使用NEST(1.8)索引字符串數組?

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

我想使用NEST(1.8)C#在彈性搜索中索引字符串數組。

這是我的映射

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; }

    }
}

我希望此字段被索引為字符串數組。

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

但是ElasticProperty中沒有像Field這樣的Field類型!

那么,我應該使用哪種FieldType或索引字符串數組數據的任何其他選項?

我將把你鏈接到彈性文檔。 數組數據類型

默認情況下,Elastic中的字段可以包含零個,一個或多個值,無需指定數組。 唯一的要求是數組中的所有數據都是相同的類型。

因此,要索引數組,請在Elastic中將Data指定為字符串,並在索引時只傳遞一個字符串數組。 Elastic會將其索引為JSON數組。

根據您發布的代碼判斷,這應該可以用來索引Data上的字符串數組。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM