我正在使用适用于 .NET 的 ElasticSearch 和 NEST C# 库迈出第一步。这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Nest;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var setting = new ConnectionSettings(new Uri("http://localhost:9200/"));
setting.SetDefaultIndex("Post");
var client = new ElasticClient(setting);
var post = new Post();
post.id = 1;
post.title = "the title";
var t = client.Index(post);
var results = client.Search<Post>(s => s.From(0)
.Size(10)
.Fields(f => f.id, f => f.title)
.Query(q => q.Term(f => f.title, "title", Boost: 2.0))
);
}
}
public class Post
{
public int id { get; set; }
public string title { get; set; }
}
我期待从 Post 1 中得到结果,因为它有“title”关键字,但我得到了空的结果集。我做错了什么?