티스토리 뷰
Elastic-builder 공식 문서에서의 Must와 Should 설명
- Must
💡 must(queries)
Adds must query to boolean container. The clause (query) must appear in matching documents and will contribute to the score.
must(queries: (Array<Query> | Query)): BoolQuery
Parameters
queries ((Array<Query> | Query)) List of valid Query objects or Query object
Returns
BoolQuery: returns this so that calls can be chained.
Throws
- TypeError: If Array item or query is not an instance of Query
- should
💡 should(queries)
Adds should query to boolean container. The clause (query) should appear in the matching document. In a boolean query with no must or filter clauses, one or more should clauses must match a document. The minimum number of should clauses to match can be set using the minimum_should_match parameter.
should(queries: (Array<Query> | Query)): BoolQuery
Parameters
queries ((Array<Query> | Query)) List of valid Query objects or Query object
Returns
BoolQuery: returns this so that calls can be chained.
Throws
- TypeError: If Array item or query is not an instance of Query
계속 등장하는 BoolQuery에 대해 👇🏻
Elastic-builder 공식 문서에서의 BoolQuery에 대한 설명
💡 Boolquery()
A query that matches documents matching boolean combinations of other queries. The bool query maps to Lucene BooleanQuery. It is built using one or more boolean clauses, each clause with a typed occurrence.
Extends Querynew BoolQuery()
Example
const qry = esb.boolQuery() .must(esb.termQuery('user', 'kimchy')) .filter(esb.termQuery('tag', 'tech')) .mustNot(esb.rangeQuery('age').gte(10).lte(20)) .should([ esb.termQuery('tag', 'wow'), esb.termQuery('tag', 'elasticsearch') ]) .minimumShouldMatch(1) .boost(1.0);
공식 문서 내용을 보고도 명확하게 이해가 되지 않아서 더 찾아보았다.
- must means: The clause (query) must appear in matching documents. These clauses must match, like logical AND.
- should means: At least one of these clauses must match, like logical OR.
Basically they are used like logical operators AND and OR. See this.
Now in a bool query:
- must means: Clauses that must match for the document to be included.
- should means: If these clauses match, they increase the _score; otherwise, they have no effect. They are simply used to refine the relevance score for each document.
출처는 글 맨 아래에 기재.
must는 AND , should는 OR 같은 개념.
References
'Elasticsearch' 카테고리의 다른 글
[Elasticsearch] Elastic-builder - 원하는 필드만 조회 (0) | 2023.02.27 |
---|
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- aws cli
- NestJS
- 도커
- serverless
- git동기화
- container접속
- Hoisting
- 웹훅
- docker
- should
- nodejs
- docker exec
- webhook
- github
- branch조회
- contentScript.js
- elastic-builder
- AWS
- 서버리스
- Lambda
- 람다
- Error "server gave HTTP response to HTTPS client"
- docker-compose
- JavaScript
- ChromeExtension
- 깃헙
- 디스코드
- elasticsearch
- background.js
- 크롬익스텐션