CodeGo.net>如何在弹性搜索中使用NEST(1.8)索引字符串数组?

我想在使用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中没有像Array这样的Field类型!

因此,我应该使用哪个FieldType或任何其他选项来索引字符串数组数据?

解决方法:

我将为此链接您到弹性文档.
array datatype

Elastic中的字段默认可以包含零个,一个或多个值,无需指定数组.唯一的要求是数组中的所有数据都属于同一类型.

因此要索引数组,请在Elastic中将Data指定为字符串,并在索引时仅传递字符串数组. Elastic会将其索引为JSON数组.

从您发布的代码来看,这应该可以为Data上的字符串数组建立索引.

上一篇:Nest中各类组件使用及请求链路


下一篇:基于FPGA的类脑计算平台 —PYNQ 集群的无监督图像识别类脑计算系统