我试图在Elasticsearch的程序中添加一些分析器。
但是在添加.Property
时会显示错误,例如
错误1'Inch.CreateIndexDescriptor'不包含'Property'的定义,并且没有扩展方法'Property'可以找到接受类型'Nest.CreateIndexDescriptor'的第一个参数(你是否缺少using指令或程序集)引用?)
你能帮我解决这个问题吗?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Nest;
using System.Data;
using System.Diagnostics;
using Microsoft.CSharp.RuntimeBinder;
using System.IO;
namespace MenuAnalyzer2
{
public 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: "asd");
client = new ElasticClient(settings);
var indexsettings = new IndexSettings();
indexsettings.NumberOfReplicas =1;
indexsettings.NumberOfShards = 6;
client.CreateIndex("asd", c => c
.Index("asd")
.InitializeUsing(indexsettings)
.Property(prop => prop
.MultiField(mf => mf
.Name(p => p.Name)
.Fields(f => f
.String(
s =>
s.Name(n => n.Name)
.IndexAnalyzer("autocomplete_analyzer")
.IncludeInAll(false)
.Index(FieldIndexOption.NotAnalyzed))
.String(
s =>
s.Name(n => n.Name)
.IndexAnalyzer("fulltext")
.IncludeInAll(false)
.Index(FieldIndexOption.NotAnalyzed))
)
)
)
.AddMapping<Items>(m => m.MapFromAttributes()));
PerformMatchPhrase();
Items obj;
string filepath = "D:\\food.csv";
DataTable res = ConvertCSVtoDataTable(filepath);
List<DataRow> list = res.AsEnumerable().ToList();
foreach (var row in list)
{
//client = new ElasticClient(settings);
obj = new Items();
obj.itemID = row.Field<string>("ID");
obj.item = row.Field<string>("Foodies");
obj.price = row.Field<string>("Amount");
obj.ac = row.Field<string>("Ac");
client.Index(obj);
}
}
public static DataTable ConvertCSVtoDataTable(string strFilePath)
{
StreamReader sr = new StreamReader(strFilePath);
string[] headers = sr.ReadLine().Split(',');
DataTable dt = new DataTable();
foreach (string header in headers)
{
dt.Columns.Add(header);
}
while (!sr.EndOfStream)
{
string[] rows = sr.ReadLine().Split(',');
DataRow dr = dt.NewRow();
for (int i = 0; i < headers.Length; i++)
{
dr[i] = rows[i];
}
dt.Rows.Add(dr);
}
return dt;
}
public static void PerformMatchPhrase()
{
List<Items> mat = new List<Items>();
var result =
client.Search<Items>(s => s
.Query(q => q.MatchPhrase(m => m.OnField("item").Query("masala"))));
//.Query(q => q.MatchAll("postText"))));
if(result!=null)
{
if (result.Documents.Count <Items>()> 0)
mat = result.Documents.ToList <Items>();
}
foreach(Items m in mat)
{
Console.WriteLine(m.itemID);
Console.WriteLine(m.item);
Console.WriteLine(m.price);
Console.WriteLine(m.ac);
}
Console.ReadLine();
}
}
}`