gpt4 book ai didi

asp.net - 带有 NEST 查询问题的 ElasticSearch

转载 作者:行者123 更新时间:2023-12-03 01:07:25 25 4
gpt4 key购买 nike

原谅我的新手,因为我是 ElasticSearch 和 NEST 的新手。我正在开发一个原型(prototype),以在正在实现的 .NET 解决方案中评估 ElasticSearch。原型(prototype)编译并且似乎搜索,但没有正确返回结果。它仅返回几个关键字的结果,仅小写,而忽略其他关键字并且不返回任何内容。我认为我的查询有问题。这是查询部分(假设指定并构建了连接信息和默认索引)。

// 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; }
}

感谢帮助!

最佳答案

您的问题是您正在使用 term queries , 不进行分析,因此区分大小写。

尝试使用 match query (已分析)改为:

var searchResults = client.Search<Product>(s => s
.From(0)
.Size(100)
.Query(q =>
q.Match(m => m.OnField(p => p.ProductName).Query(searchString)) ||
q.Match(m => m.OnField(p => p.Description).Query(searchString))
)
);

更进一步——因为您在两个不同的字段上查询相同的文本,您可以使用 multi match query而不是结合两个术语查询:
var searchResults = client.Search<Product>(s => s
.From(0)
.Size(100)
.Query(q => q
.MultiMatch(m => m
.OnFields(p => p.Product, p => p.Description)
.Query(searchText)
)
)
);

为了更好地理解分析, mapping and analysis来自 The Definitive Guide 的部分是一本很棒的书。

关于asp.net - 带有 NEST 查询问题的 ElasticSearch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25536429/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com