【问题标题】:ElasticSearch: How to fetch data from fields using ElasticClient from Nest 7.11?ElasticSearch:如何使用 Nest 7.11 中的 ElasticClient 从字段中获取数据?
【发布时间】:2021-03-05 11:49:58
【问题描述】:

我正在使用 ElasticClient.Search 函数来获取字段的值。

问题是:

我在下面制作的代码使映射正确,但搜索它返回之前映射的字段的空值。

Main.cs

using Nest;
using System;
using System.Linq;
using System.Threading;

namespace DataAccessConsole
{
  class Program
  {
      public static Uri node;
      public static ConnectionSettings settings;
      public static ElasticClient client;
      static void Main(string[] args)
      {
          {
            node = new Uri("http://localhost:9200");
              settings = new ConnectionSettings(node).DefaultIndex("getallcommissionspermanentes");
              settings.DefaultFieldNameInferrer(p => p);
              client = new ElasticClient(settings);

              var indexSettings = new IndexSettings();
              indexSettings.NumberOfReplicas = 1;
              indexSettings.NumberOfShards = 1;

              client.Indices.Create("getallcommissionspermanentes", index => index

              .Map<GetAllCommissionsPermanentes>(
                   x => x
                   .AutoMap<GetAllCommissionsPermanentes>()

              ));


               client.Search<GetAllCommissionsPermanentes>(s => s
               .AllIndices()
               );

  }
}

GetAllCommissionsPermanentes.cs

该表位于实体框架的 edmx 模型中,数据来自 SQL SERVER 数据库

    public partial class GetAllCommissionsPermanentes
    {
        public int ID { get; set; }
        public string NomAr { get; set; }
        public string NomFr { get; set; }
    }

如果您需要更多信息,请在下方发表评论。

谢谢

【问题讨论】:

    标签: c# .net elasticsearch nest


    【解决方案1】:

    代码是正确的,但是 '.All Indices ()' 在所有索引中搜索,与模型不匹配的结果即将到来。此代码将返回更准确的结果;

    client.Search<GetAllCommissionsPermanentes>(s => s.Index("getallcommissionspermanentes");
    

    【讨论】:

      猜你喜欢
      • 2019-08-05
      • 1970-01-01
      • 2019-05-03
      • 1970-01-01
      • 1970-01-01
      • 2019-08-04
      • 2015-05-15
      • 1970-01-01
      • 2021-07-27
      相关资源
      最近更新 更多