'search query'에 해당되는 글 1건

  1. 2013.01.09 elasticsearch query uri 예제들.

elasticsearch query uri 예제들.

Elastic/Elasticsearch 2013. 1. 9. 12:02

기본적으로 /_plugin/head 에서 structured query 를 만들수 있지만 좀 더 다양한 옵션을 주고 싶을 경우 추가 구성을 해야 합니다.
elasticsearch.org 문서만 가지고 만들다 보면 처음 접하시는 분들은 어떻게 시작할지 막막할 수 있죠.
그래서 제가 테스트 했던 것들 올려 봅니다.


[기본쿼리]
http://localhost:9200/jjeong0/_search?q=msg:채팅&pretty=true
- msg 라는 field 에 대해서 검색 수행

http://localhost:9200/jjeong0/_search?q=msg:안녕 OR title:안녕하세요&sort=cre_ymdt:desc&from=0&size=10&pretty=true
- msg 와 title field 에 대해서 OR 검색을 수행


[JSON String Type]
[Paging+term 기반 쿼리]

http://localhost:9200/jjeong0/_search?source={"from":0,"size":10,"query":{"term":{"msg":"안녕하세요"}}}&pretty=true
- msg 라는 field 에 대해서 term 기반으로 검색 수행
- from 은 시작 offset 값이며, size 는 한 번에 fetch 해올 문서 크기

[Sorting + term 기반 쿼리]
http://localhost:9200/jjeong0/_search?source={"query":{"bool":{"must":[{"term":{"msg":"안녕"}}],"must_not":[],"should":[]}},"from":0,"size":50,"sort":[{"cre_ymdt":"asc"}],"facets":{}}&pretty=true
- msg 에 반드시 "안녕" 이라는 단어가 포함이 된 것만 검색
- cre_ymdt 값에 대한 ascending sorting
- http://www.elasticsearch.org/guide/reference/api/search/sort.html

[Range Search]
http://localhost:9200/jjeong0/_search?source={"query":{"range":{"recv_ymdt":{"from":"20120820163946", "to":"20120911160444"}}}}&pretty=true
- recv_ymdt 라는 값에 대해서 범위를 지정하고 검색
- http://www.elasticsearch.org/guide/reference/query-dsl/range-query.html

[Query String Search]
http://localhost:9200/jjeong0/_search?source={"query":{"bool":{"must":[{"query_string":{"default_field":"msg","query":"%EC%95%88%EB%85%95%ED%95%98%EC%84%B8%EC%9A%94"}}],"must_not":[],"should":[]}},"from":0,"size":50,"sort":[{"cre_ymdt":"desc"}],"facets":{}}&pretty=true
- http://www.elasticsearch.org/guide/reference/query-dsl/query-string-query.html

[Highlight Search]
http://localhost:9200/jjeong0/_search?source={"query":{"bool":{"must":[{"query_string":{"default_field":"msg","query":"안녕 하세요"}}],"must_not":[],"should":[]}},"from":0,"size":50,"sort":[{"cre_ymdt":"desc"}],"facets":{},"highlight":{"pre_tags":["<b>"],"post_tags":["</b>"],"fields":{"msg":{}}}}&pretty=true
- http://www.elasticsearch.org/guide/reference/api/search/highlighting.html

[Term+QueryString+Range+Highlight, Sort, Paging, Routing]
http://localhost:9200/jjeong0/_search?source={"from":0,"size":20,"query":{"bool":{"must":[{"term":{"user_uniq_id":"jjeong.tistory.com"}},{"query_string" : {"default_operator" : "OR","fields" : ["msg", "title"],"query" : "안먹어"}},{"range":{"rm_ymdt":{"from":"20121209000000","to":"20130110000000","include_lower":true,"include_upper":true}}}]}},"highlight":{"pre_tags":["<b>"],"post_tags":["</b>"],"fields":{"msg":{},"title":{}}},"sort":[{"cre_ymdt":{"order":"desc"}}]}&routing=jjeong.tistory.com&pretty=true
- http://www.elasticsearch.org/guide/reference/mapping/routing-field.html


: