gpt4 book ai didi

c# - Elasticsearch-Nest-特定搜索

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

关于这个问题:
Elasticsearch/Nest - using MatchPhrase with OnFieldsWithBoost

我有一个看起来像这样的索引:

{
"_index": "myIndex",
"_type": "Page",
"_id": "119",
"_score": 0.104187615,
"_source": {
"dataBaseId": 119,
"category": "InfoPage",
"type": "Page",
"metaTitle": "myMeta",
"metaDescription": "Description",
"rawText": "my search text"
}
}

我的代码如下所示:
var result = ElasticClient.Search<SearchReportDocument>(s => s
.Index("myIndex")
.Type("Page")
.Size(10)
.Query(q =>
q.MultiMatch(m => m.OnFieldsWithBoost(f => f.Add(b => b.MetaTitle, 5).Add(b => b.RawText, 1)).Type(TextQueryType.PhrasePrefix).Query(searchQuery))
)
);

我想将其扩展为仅返回“类别”等于InfoPage的结果。

最佳答案

根据索引的结构,我假设您有一个Page类,因此您可以找到具有该类别的页面,如下所示:

 var result= client.Search<Page>(sd => sd.Index("myIndex")
.From(0)
.Size(10).Query(q =>
q.MultiMatch( m =>
m.OnFieldsWithBoost(f => f.Add(b => b.MetaTitle, 5).Add(b => b.RawText, 1))
.Type(TextQueryType.PhrasePrefix)
.Query(searchQuery))
&& q.Term("category", "infopage")));

现在,如果 SearchReportDocument类具有 Page的相同字段,那么您也可以通过以下方式找到页面:
  var result= client.Search<SearchReportDocument>(sd => sd.Index("myIndex").Type("Page")
.From(0)
.Size(10).Query(q =>
q.MultiMatch( m =>
m.OnFieldsWithBoost(f => f.Add(b => b.MetaTitle, 5).Add(b => b.RawText, 1))
.Type(TextQueryType.PhrasePrefix)
.Query(searchQuery))
&& q.Term("category", "infopage")));

关于c# - Elasticsearch-Nest-特定搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28239926/

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