samsung notebook이라는 상품을 simsung notebook이라고 검색해도 조회가 돼야 한다. 상품명에서 일치하는 검색 키워드는 하이라이팅 처리( <b></b>)를 해야 한다.should를 활용하면 된다. GET /products/_search { "query": { "bool": { "must": { "multi_match": { "query": "LG 냉장고", "fields": [ "name^3", "description^1", "category^2" ] } }, "filter": [ { "term": { "category.raw": "가전제품" } }, { "range": { "price": { "gte": 10000, "lte": 50000 } } } ], "should": [ { "range": { "rating": { "gt": 4.0 } } } ] } } }
GET /products/_search { "query": { "bool": { "must": { "multi_match": { "query": "마전제품", "fields": [ "name^3", "description^1", "category^2" ], "fuzziness": "AUTO" } }, "filter": [ { "term": { "category.raw": "가전제품" } }, { "range": { "price": { "gte": 10000, "lte": 50000 } } } ], "should": [ { "range": { "rating": { "gt": 4.0 } } } ] } } }
상품명에서 일치하는 검색 키워드는 하이라이팅 처리( <b></b>) 하기GET /products/_search { "query": { "bool": { "must": { "multi_match": { "query": "삼성", "fields": [ "name^3", "description^1", "category^2" ], "fuzziness": "AUTO" } }, "filter": [ { "term": { "category.raw": "가전제품" } }, { "range": { "price": { "gte": 10000, "lte": 50000 } } } ], "should": [ { "range": { "rating": { "gt": 4.0 } } } ] } }, "highlight": { "fields": { "name": { "pre_tags": ["<b>"], "post_tags": ["</b>"] } } } }
GET /products/_search { "query": { "bool": { "must": { "multi_match": { "query": "삼성", "fields": [ "name^3", "description^1", "category^2" ], "fuzziness": "AUTO" } }, "filter": [ { "term": { "category.raw": "가전제품" } }, { "range": { "price": { "gte": 10000, "lte": 50000 } } } ], "should": [ { "range": { "rating": { "gt": 4.0 } } } ] } }, "highlight": { "fields": { "name": { "pre_tags": ["<b>"], "post_tags": ["</b>"] } } }, "from": 0, // 몇 번째 데이터부터 조회할 건지 = (페이지 번호 - 1) x size "size": 5 // 페이지당 몇 개의 데이터를 조회할 지 }
검색 기능의 요구 사항을 전부 만족시켰다. 그럼 다음 기능인 자동 완성 기능의 요구사항을 만족시켜보자.