elasticsearch,nest,C#,elasticsearch,Nest" /> elasticsearch,nest,C#,elasticsearch,Nest" />

嵌套-无法为对象编制索引(c#搜索)

嵌套-无法为对象编制索引(c#搜索),c#,elasticsearch,nest,C#,elasticsearch,Nest,我抓取了NEST的最新版本,并尝试实现简单的弹性搜索。我的代码不为对象编制索引。IsValid返回false,但我不知道为什么。结果也是空的。 这是我的代码片段。我会感谢你的帮助 public ActionResult Search() { var node = new Uri("http://localhost:49997"); var settings = new ConnectionSettings(

我抓取了NEST的最新版本,并尝试实现简单的弹性搜索。我的代码不为对象编制索引。IsValid返回false,但我不知道为什么。结果也是空的。 这是我的代码片段。我会感谢你的帮助

public ActionResult Search()
        {
            var node = new Uri("http://localhost:49997");

            var settings = new ConnectionSettings(
                node,
                defaultIndex: "my-application"
            );

            var client = new ElasticClient(settings);

            var uporabnik = new uporabnik
            {
                idUporabnik = 99,
                ime = "John",
                priimek = "Schwarz"
            };

            var index = client.Index(uporabnik);
            if (!index.IsValid)
            {
                Log.Error("Error when indexing.");
            }

            var results = client.Search<uporabnik>(s => s.Query(q => q.Term(p => p.priimek, "Novak")));

            return View();
        }
公共操作结果搜索()
{
var node=新Uri(“http://localhost:49997");
var设置=新连接设置(
节点,
defaultIndex:“我的应用程序”
);
var客户端=新的ElasticClient(设置);
var uporabnik=新的uporabnik
{
idUporabnik=99,
ime=“约翰”,
priimek=“Schwarz”
};
var指数=客户指数(uporabnik);
如果(!index.IsValid)
{
Log.Error(“索引时出错”);
}
var results=client.Search(s=>s.Query(q=>q.Term(p=>p.priimek,“Novak”));
返回视图();
}
我尝试了Console.WriteLine(index.ServerError.Error),但出现了一个错误:对象引用未设置为对象的实例。所以我不知道,什么是错误信息

下面是uporabnik类

public partial class uporabnik
    {
        public uporabnik()
        {
            this.ocena = new HashSet<ocena>();
            this.predmet = new HashSet<predmet>();
            this.studentpredmet = new HashSet<studentpredmet>();
        }

        [Required]
        public int idUporabnik { get; set; }

        public Nullable<int> vpisnaStevilka { get; set; }

        [Required]
        [RegularExpression(@"^[A-z]*$"]
        public string ime { get; set; }

        [Required]
        [RegularExpression(@"^[A-z]*$"]
        public string priimek { get; set; }

        [RegularExpression(@"^[\w\d-\.]+@([\w\d-]+\.)+[\w-]{2,4}$"]
        public string email { get; set; }

        public string geslo { get; set; }

        [Required]
        public string mobi { get; set; }

        [Required]
        [RegularExpression(@"^[MZ]*$"]
        public string spol { get; set; }

        [RegularExpression(@"^[123]{1}$"]
        public Nullable<int> letnikStudija { get; set; }

        public System.DateTime datumRegistracije { get; set; }

        public System.DateTime zadnjiDostop { get; set; }

        public int idVloge { get; set; }

        [JsonIgnore]
        public virtual ICollection<ocena> ocena { get; set; }

        [JsonIgnore]
        public virtual ICollection<predmet> predmet { get; set; }

        [JsonIgnore]
        public virtual ICollection<studentpredmet> studentpredmet { get; set; }

        [JsonIgnore]
        public virtual vloga vloga { get; set; }
    }
公共部分类uporabnik
{
公共uporabnik()
{
this.ocena=新的HashSet();
this.predmet=new HashSet();
this.studentpredmet=new HashSet();
}
[必需]
public int idUporabnik{get;set;}
公共可为空的vpisnaStevilka{get;set;}
[必需]
[正则表达式(@“^[A-z]*$”]
公共字符串ime{get;set;}
[必需]
[正则表达式(@“^[A-z]*$”]
公共字符串priimek{get;set;}
[正则表达式(@“^[\w\d-\.]+@([\w\d-]+\.)+[\w-]{2,4}$”]
公共字符串电子邮件{get;set;}
公共字符串geslo{get;set;}
[必需]
公共字符串mobi{get;set;}
[必需]
[正则表达式(@“^[MZ]*$”]
公共字符串spol{get;set;}
[正则表达式(@“^[123]{1}$”]
公共可为空的letnikStudija{get;set;}
public System.DateTime datumRegistracije{get;set;}
public System.DateTime zadnjiDostop{get;set;}
public int idVloge{get;set;}
[JsonIgnore]
公共虚拟ICollection ocena{get;set;}
[JsonIgnore]
公共虚拟ICollection预集合{get;set;}
[JsonIgnore]
公共虚拟ICollection StudentPreMet{get;set;}
[JsonIgnore]
公共虚拟vloga vloga{get;set;}
}

您可以从
index.ServerError.Error
发布
uporabnik
类和消息吗?