简体   繁体   English

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

[英]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#. 我想使用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! 但是ElasticProperty中没有像Field这样的Field类型!

So, Which FieldType I should use or Any other options to Index String Array Data? 那么,我应该使用哪种FieldType或索引字符串数组数据的任何其他选项?

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. 默认情况下,Elastic中的字段可以包含零个,一个或多个值,无需指定数组。 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中将Data指定为字符串,并在索引时只传递一个字符串数组。 Elastic will index it as a JSON array. Elastic会将其索引为JSON数组。

Judging by the code you posted, that should work to index an array of strings on Data. 根据您发布的代码判断,这应该可以用来索引Data上的字符串数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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