[Elasticsearch] Query DSL - Filters

Elastic/Elasticsearch 2013. 4. 18. 10:46

본 문서는 개인적인 테스트와 elasticsearch.org 그리고 community 등을 참고해서 작성된 것이며,

정보 교환이 목적입니다.


잘못된 부분에 대해서는 지적 부탁 드립니다.

(예시 코드는 성능 및 보안 검증이 되지 않았습니다.)



[elasticsearch API 리뷰]

원문 링크 : http://www.elasticsearch.org/guide/reference/query-dsl/

- 많이 사용되는 것들로 진행 합니다.



 

Queries

Filters

 


















[Filters]

기본적으로 filtered query 에서 동작 방식을 소개 했기 때문에 이 점을 이해하고 보셔야 합니다.


[and/or]

- 쿼리 결과에 대한 추가 쿼리의 and/or 연산을 수행 합니다.

- 쿼리 결과를 cache 하고 싶을 경우 _cache:true 설정을 하면 됩니다.


[bool]

- boolean 쿼리를 추가 수행 합니다.


[exists]

- 결과에 대해서 항상 cache 합니다.


[ids]

- ids 를 포함한 문서를 필터 합니다.


[limit]

- shard 당 문서 수를 제한 합니다.


[type]

- document/mapping type 에 대한 filter 합니다.


[missing]

- 문서의 특정 필드 값이 no value 인 것을 filter 합니다.

- 지정된 field 는 null_value 를 갖습니다.

- 예제가 직관적이기 떄문에 추가 합니다.

{
    "constant_score" : {
        "filter" : {
            "missing" : { 
                "field" : "user",
                "existence" : true,
                "null_value" : true
            }
        }
    }
}


[not]

- 질의된 결과에 대해서 추가로 주어진 not filter 로 match 된 문서를 제외 합니다.


[numeric range]

- range filter와 유사하며, 어떤 수의 범위를 갖습니다.

- 주어진 parameters 는 아래와 같습니다.

NameDescription
fromThe lower bound. Defaults to start from the first.
toThe upper bound. Defaults to unbounded.
include_lowerShould the first from (if set) be inclusive or not. Defaults to true
include_upperShould the last to (if set) be inclusive or not. Defaults to true.
gtSame as setting from and include_lower to false.
gteSame as setting from and include_lower to true.
ltSame as setting to and include_upper to false.
lteSame as setting to and include_upper to true.

[prefix]

- phrase query 와 유사하며,  prefix query 참고


[query]

- 추가 query 를 생성 할 수 있습니다.


[range]

- range query 참고


[script]

- script 를 이용한 filter 를 적용 할 수 있습니다.


[term]

- term query 참고


[terms]

- terms query 참고

- execution mode 를 지원 합니다.

- 기본 plain 그리고 bool, and, or 지원


[nested]

- nested query 참고


※ filter 의 경우 기본 query 에서 제공 하는 것과 거의 동일 하며,

이 API 의 목적은 한번 질의한 결과에 대해 별도의 filtering 을 하기 위함 입니다.


: