- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用NGram在多个字段上使用ElasticSearch进行部分匹配,但是在建立索引后我将匹配0个结果。这对我来说不是很自然,而且我什至无法让NGram在一个 Realm 工作。对我来说,这是一个充满激情的项目,我真的希望新的搜索可以部分匹配单词。我尝试使用模糊性,但它开始对不正确的匹配评分很高。
索引创建:
var nGramFilters = new List<string> { "lowercase", "asciifolding", "nGram_filter" };
Client.Indices.Create(CurrentIndexName, c => c
.Settings(st => st
.Analysis(an => an // https://stackoverflow.com/questions/38065966/token-chars-mapping-to-ngram-filter-elasticsearch-nest
.Analyzers(anz => anz
.Custom("ngram_analyzer", cc => cc
.Tokenizer("ngram_tokenizer")
.Filters(nGramFilters))
)
.Tokenizers(tz => tz
.NGram("ngram_tokenizer", td => td
.MinGram(2)
.MaxGram(20)
.TokenChars(
TokenChar.Letter,
TokenChar.Digit,
TokenChar.Punctuation,
TokenChar.Symbol
)
)
)
)
)
.Map<Package>(map => map
.AutoMap()
.Properties(p => p
.Text(t => t
.Name(n => n.Title)
.Fields(f => f
.Keyword(k => k
.Name("keyword")
.IgnoreAbove(256)
)
.Text(tt => tt
.Name("ngram")
.Analyzer("ngram_analyzer")
)
)
)
.Text(t => t
.Name(n => n.Summary)
.Fields(f => f
.Keyword(k => k
.Name("keyword")
.IgnoreAbove(256)
)
.Text(tt => tt
.Name("ngram")
.Analyzer("ngram_analyzer")
)
)
)
.Text(t => t
.Name(n => n.PestControlledBy)
.Fields(f => f
.Keyword(k => k
.Name("keyword")
.IgnoreAbove(256)
)
.Text(tt => tt
.Name("ngram")
.Analyzer("ngram_analyzer")
)
)
)
.Text(t => t
.Name(n => n.PesticideControlsThesePests)
.Fields(f => f
.Keyword(k => k
.Name("keyword")
.IgnoreAbove(256)
)
.Text(tt => tt
.Name("ngram")
.Analyzer("ngram_analyzer")
)
)
)
.Text(t => t
.Name(n => n.PesticideInstructions)
.Fields(f => f
.Keyword(k => k
.Name("keyword")
.IgnoreAbove(256)
)
.Text(tt => tt
.Name("ngram")
.Analyzer("ngram_analyzer")
)
)
)
.Text(t => t
.Name(n => n.PesticideActiveIngredients)
.Fields(f => f
.Keyword(k => k
.Name("keyword")
.IgnoreAbove(256)
)
.Text(tt => tt
.Name("ngram")
.Analyzer("ngram_analyzer")
)
)
)
.Text(t => t
.Name(n => n.PesticidesContainingThisActiveIngredient)
.Fields(f => f
.Keyword(k => k
.Name("keyword")
.IgnoreAbove(256)
)
.Text(tt => tt
.Name("ngram")
.Analyzer("ngram_analyzer")
)
)
)
.Text(t => t
.Name(n => n.PesticideSafeOn)
.Fields(f => f
.Keyword(k => k
.Name("keyword")
.IgnoreAbove(256)
)
.Text(tt => tt
.Name("ngram")
.Analyzer("ngram_analyzer")
)
)
)
.Text(t => t
.Name(n => n.PesticideNotSafeOn)
.Fields(f => f
.Keyword(k => k
.Name("keyword")
.IgnoreAbove(256)
)
.Text(tt => tt
.Name("ngram")
.Analyzer("ngram_analyzer")
)
)
)
)
)
);
var result = _client.Search<Package>(s => s
.From((form.Page - 1) * form.PageSize)
.Size(form.PageSize)
.Query(query => query
.MultiMatch(m => m
.Fields(f => f
.Field(p => p.Title.Suffix("ngram"), 1.5)
.Field(p => p.Summary.Suffix("ngram"), 1.1)
.Field(p => p.PestControlledBy.Suffix("ngram"), 1.0)
.Field(p => p.PesticideControlsThesePests.Suffix("ngram"), 1.0)
.Field(p => p.PesticideInstructions.Suffix("ngram"), 1.0)
.Field(p => p.PesticideActiveIngredients.Suffix("ngram"), 1.0)
.Field(p => p.PesticidesContainingThisActiveIngredient.Suffix("ngram"), 1.0)
.Field(p => p.PesticideSafeOn.Suffix("ngram"), 1.0)
.Field(p => p.PesticideNotSafeOn.Suffix("ngram"), 1.0)
)
.Operator(Operator.Or) // https://stackoverflow.com/questions/46139028/elasticsearch-how-to-do-a-partial-match-from-your-query
.Query(form.Query)
)
)
.Highlight(h => h
.PreTags("<strong>")
.PostTags("</strong>")
.Encoder(HighlighterEncoder.Html) //https://github.com/elastic/elasticsearch-net/issues/3091
.Fields(fs => fs
.Field(f => f.Summary.Suffix("ngram")),
fs => fs
.Field(p => p.PestControlledBy.Suffix("ngram")),
fs => fs
.Field(p => p.PesticideControlsThesePests.Suffix("ngram")),
fs => fs
.Field(p => p.PesticideInstructions.Suffix("ngram")),
fs => fs
.Field(p => p.PesticideActiveIngredients.Suffix("ngram")),
fs => fs
.Field(p => p.PesticidesContainingThisActiveIngredient.Suffix("ngram")),
fs => fs
.Field(p => p.PesticideSafeOn.Suffix("ngram")),
fs => fs
.Field(p => p.PesticideNotSafeOn.Suffix("ngram"))
.NumberOfFragments(10)
.FragmentSize(250)
)
)
);
最佳答案
client.Indices.Create
调用无效,其原因有两个:
MinGram
和MaxGram
之间的差不能大于1,因此会出现此错误Elasticsearch.Net.ElasticsearchClientException: Request failed to execute. Call: Status code 400 from: PUT /my_index1?pretty=true&error_trace=true. ServerError: Type: illegal_argument_exception Reason: "The difference between max_gram and min_gram in NGram Tokenizer must be less than or equal to: [1] but was [18]. This limit can be set by changing the [index.max_ngram_diff] index level setting."
nGram_filter
这样的过滤器,您需要将其更改为ngram
DebugInformation
必须告诉我什么
var createIndexResponse = await client.Indices.CreateAsync("my_index1", ..);
createIndexResponse.DebugInformation
关于c# - .NET ElasticSearch NEST-用于部分匹配的多个字段上的NGram分析器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60160108/
在查看Thermostat Guide时,我没有提到湿度读数。这些数据可以通过API获得吗?会在以后的版本中吗? 最佳答案 从NestAPI v1.1开始,似乎湿度数据可以作为只读字段使用。 可以在v
我从以下位置获取了授权码 https://home.nest.com/login/oauth2?client_id=CLIENT_ID&state=FOO . 我想获取access_token,但是出
使用1.1.2版本的Nest,似乎至少有3种索引多个文档的方法: IndexMany client.IndexMany(documents, "index_name", "type_name"); 使
我有2个POJO(人和车),其中一个由另一个人引用 @Document(indexName = "person", type = "user") public class Person { @
Nest Protect(烟雾和一氧化碳警报)可以测量温度和湿度,但官方或非官方 API 似乎都不允许访问这些数据。有人在工作吗?任何视线访问这些数据?建议?谢谢! 最佳答案 $infos = (o
自从我得到 Nest 以来,我所想要的就是能够在很长一段时间内汇总我的能量使用情况以寻找模式,主要是满足我的好奇心。当然有每月使用报告,而且网络和设备只能追溯到 10 天。 API 是否公开了这些数据
我在获取和更改 Nest 恒温器提供的一些基本数据时遇到了问题。 使用命令行,我如何获取或更改恒温器上的个别设置或值? 最佳答案 这是几个用户的汇编,解释了如何检索或更改一些基本信息,并添加了我自己的
我和我的一位同事就以下最佳实践问题进行了讨论。 大多数函数/方法都从一些参数检查开始。 我提倡以下风格,避免嵌套。 if (parameter one is ugly) return ERROR; i
我有 4 个表: ChatRooms Participants Messages Users 聊天室有很多参与者 聊天室有很多消息 用户有很多消息 用户有很多参与者 参与者属于用户 消息属于用户 我正
我编写了以下函数并得到如下所示的响应: public async Task ShowMapping(string indexname) { var resu
我正在使用 NEST 为我的对象编制索引,但在序列化时遇到了 Newtonsoft 错误。我的一个对象有一个自引用循环。有没有一种方法可以让我访问 JsonSerializer 并更改它处理自引用的方
设置目标温度会引发如下错误。我正在使用 php curl 来设置温度。任何帮助表示赞赏。 object(stdClass)#72 (2) { ["cmd"]=> stri
我编写了以下函数并得到如下所示的响应: public async Task ShowMapping(string indexname) { var resu
我正在使用 Nest Developer https://developer.nest.com/用于创建 iOS 应用程序的 API。有谁知道如何将 Firebase 框架链接到我的应用程序中?我不断
我是名为 Feather (featherapp.co) 的综合性 Apple TV 应用程序的开发者。我遇到的一个问题是用户希望能够查看他们相机的实时画面。 有没有人确定访问摄像头实时画面的方法?我
免责声明 - 我担心这个问题可能是重复的,因为功能看起来很基本,所以我知道我可能会得到一个骗局。但我找不到有效的解决方案 所以我有一个可观察的数组设置如下 self.meetingAttendees
我正试着给我的模块提供一个令牌。该模块如下所示:。我将AuthGuardModule导入到的父模块如下所示:。而gardConfigProvider本身如下所示:。但我得到一个错误:Error[Exc
我正试着给我的模块提供一个令牌。该模块如下所示:。我将AuthGuardModule导入到的父模块如下所示:。而gardConfigProvider本身如下所示:。但我得到一个错误:Error[Exc
每 10 秒使用一次访问 token 时遇到太多请求错误。在重新阅读文档时,我意识到这是一个禁忌(“为了避免错误,我们建议您以每分钟一次或更短的速度提出请求”)。 有谁知道我会被限制多久? 最佳答案
我使用嵌套 plist 来创建对象结构(CLOS 类型),将嵌套的对象传递给它的部分。我想以迭代方式 append 嵌套的 plist,但因此我想在时间和内存方面高效地完成它。 以下示例显示了由于一次
我是一名优秀的程序员,十分优秀!