我正在使用帶有彈性搜索 DB 的 NODE JS。我正在使用這個包 https://www.npmjs.com/package/@elastic/elasticsearch 我的彈性搜索資料庫中有這個集合
[
{
"_index": "products",
"_id": "wZRh3n8Bs9qQzO6fvTTS",
"_score": 1.0,
"_source": {
"title": "laptop issues",
"description": "laptop have issue present in according"
}
},
{
"_index": "products",
"_id": "wpRh3n8Bs9qQzO6fvzQM",
"_score": 1.0,
"_source": {
"title": "buy mobile",
"description": "mobile is in Rs 250"
}
},
{
"_index": "products",
"_id": "w5Rh3n8Bs9qQzO6fvzTz",
"_score": 1.0,
"_source": {
"title": "laptop payment",
"description": "laptop payment is given in any way"
}
}
]
現在我打算從彈性資料庫中獲取資料。當我通過 "LAP" 或 "lap" 時。它給了我空白陣列或[]陣列為什么?“圈”存在于所有物件中
我正在這樣做
const result= await client.search({
index: 'products',
query: {
match_phrase: {
description: "lap"
}
}
我在哪里做錯了。我需要存在lap 關鍵字的所有結果
uj5u.com熱心網友回復:
匹配查詢不起作用,因為您正在嘗試搜索laptop術語的部分字符。
您可以對單個術語使用前綴查詢,如下所示:
{
"query": {
"prefix": {
"title": {
"value": "lap"
}
}
}
}
如果要搜索短語,則可以使用短語前綴查詢:
{
"query": {
"match_phrase_prefix": {
"title": "lap"
}
}
}
如果您只想匹配查詢中的某些單詞,則可以使用match querywith operatorset to or。
POST querycheck/_search
{
"query": {
"match": {
"title": {
"query": "i have issues",
"operator": "or"
}
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/453278.html
標籤:javascript 节点.js 弹性搜索 弹性堆栈
下一篇:如何知道彈性搜索集群中的總節點?
