原諒我的新手性,因爲我對ElasticSearch和NEST都是新手。我正在製作一個原型來評估正在實施的.NET解決方案中的ElasticSearch。原型編譯並似乎搜索,但沒有正確返回結果。它只返回幾個關鍵字的結果,只是小寫,而忽略其他關鍵字並不返回任何內容。我在想我的查詢有問題。這裏是查詢部分(假定連接信息和默認索引指定和構建)。帶NEST查詢問題的ElasticSearch
// string searchString to be searched against ProductName and Description fields.
var searchResults = client.Search<Product>(s=>s
.From(0)
.Size(100)
.Query(q=>q.Term(p=>p.ProductName, searchString) ||
q.Term(p=>p.Description, searchString)
));
這裏的模型如果需要的話:
[ElasticType(IdProperty = "ProductID")]
public class Product
{
[ScaffoldColumn(false)]
[JsonIgnore]
public int ProductID { get; set; }
[Required, StringLength(100), Display(Name = "Name")]
public string ProductName { get; set; }
[Required, StringLength(10000), Display(Name = "Product Description"), DataType(DataType.MultilineText)]
public string Description { get; set; }
public string ImagePath { get; set; }
[Display(Name = "Price")]
public double? UnitPrice { get; set; }
public int? CategoryID { get; set; }
[JsonIgnore]
public virtual Category Category { get; set; }
}
感謝幫助!
您是否確實希望產品名稱和說明符合您的搜索字符串? – 2014-08-27 21:46:41
我希望它可以匹配,並且是的,我確實使用了OR運算符以及幾乎沒有變化。 – Michael 2014-08-27 23:49:59
更新:好的,顯然我沒有去過OR運算符。現在搜索工作更好,除了它似乎弄亂了字母的情況.... 「Custom」不返回任何內容,但「custom」返回「Kat Custom Car」... – Michael 2014-08-27 23:56:26