0
我有索引名爲字典,其中包含像關鍵字,映射關鍵字和類別過濾器字段。多個子查詢裏面一個查詢elasticsearch
Keyword Mapped Keyowrd Category
------- -------------- --------
apple apple iphone smartphones
apple apple watch smart watches
apple apple ipad tablets
因此,如果用戶搜索蘋果,內部查詢將搜索帶有各自類別的映射關鍵字,如下查詢。
SELECT * FROM products where (title= "*apple*" AND title="*iphone*" and category="smartphones") OR (title= "*apple*" AND title="*ipad*" and category="tablets") OR (title= "*apple*" AND title="*watch*" and category="smart watches")
下面是我寫的相應的彈性搜索查詢。
{
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"match" : {
"title" : {
"query" : "apple iphone",
"operator" : "and"
}
}
},
{
"term": {
"category.raw": "smartphones"
}
}
]
}
},
{
"bool": {
"must": [
{
"match" : {
"title" : {
"query" : "apple watch",
"operator" : "and"
}
}
},
{
"term": {
"category.raw": "smartwatch"
}
}
]
}
},
{
"bool": {
"must": [
{
"match" : {
"title" : {
"query" : "apple ipad",
"operator" : "and"
}
}
},
{
"term": {
"category.raw": "tablets"
}
}
]
}
}
],
"minimum_should_match": 1
}
}
}
- 是上面的查詢嗎?上述查詢中需要的任何更改?
- 有沒有辦法通過在這個查詢中添加一些參數來獲得elasticsearch中每個子查詢的前10個結果?