0
辞書には、キーワード、マップされたキーワードとカテゴリフィルタのようなフィールドが含まれています。1つのクエリ内で複数のサブクエリelasticsearch
ユーザーがappleを検索すると、内部的にクエリは、下のクエリとしてそれぞれのカテゴリのマッピングされたキーワードを検索します。
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個の結果を得る方法はありますか?