BigData

[ElasticSearch] Query DSL

IT오이시이 2014. 10. 13. 10:28
728x90

 

http://www.elasticsearchtutorial.com/basic-elasticsearch-concepts.html

[ElasticSearch] Query DSL

 

curl - POST "http://localhost:9200/blog/_search?pretty=true" -d 
   {"from": 0,
    "size": 10,
    "query" : QUERY_JSON,
              FILTER_JSON,
              FACET_JSON,
              SORT_JSON
 }

 

Common Solr Queries in ElasticSearch Query DSL

 

Basic select, with specific field

http://www.elasticsearchtutorial.com/common-solr-queries-in-elasticsearch.html

 http://localhost:8983/solr/select?q=lucene&fl=title

{
    "query": {
        "query_string": {
            "query": "lucene",
            "fields": ["title"]
        }
    }
}

 

Query fields (qf param)

http://localhost:8983/solr/select?q=lucene&fl=title&qf=title^10+body^2

{
    "query": {
        "query_string": {
            "query": "lucene",
            "fields": ["title^10","body^2"]
        }
    }
}

 

Filter queries (fq param)

http://localhost:8983/solr/select?q=lucene&fq=name:elastic&fq=name:search

{
  "query": {
    "filtered": {
      "query": {
        "query_string": {
          "query": "lucene"
        }
      },
      "filter": {
        "and": [
          {
            "query": {
              "query_string": {
                "query": "name:elastic"
              }
            }
          },
          {
            "query": {
              "query_string": {
                "query": "name:search"
              }
            }
          }
        ]
      }
    }
  }
}

 

Facets

http://localhost:8983/solr/select?q=lucene&facet=on&facet.fl=category{
  "query": {
    "query_string": {
      "query": "lucene"
    }
  },
  "facets": {
    "category": {
      "terms": {
        "field": "category",
        "size": 10
      }
    }
  }
}

Geo-Spatial search (within x km of a point)

 

http://localhost:8983/solr/select?q=*:*&fq={!geofilt pt=45.15,-93.85 sfield=store d=25}

{
  "query": {
    "filtered": {
      "query": {
        "match_all": {}
      },
      "filter": {
        "geo_distance": {
          "distance": "25km",
          "pin.location": {
            "lat": 45.15,
            "lon": -93.85
          }
        }
      }
    }
  }
}

 

참고할 싸이트

[Querying ElasticSearch - A Tutorial and Guide]http://okfnlabs.org/blog/2013/07/01/elasticsearch-query-tutorial.html#filter-on-one-field

[easy-to-use Javascript Library for ElasticSearch ]http://okfnlabs.org/projects/elasticsearch-js/

 

 

  • Terms - counts by distinct terms (values) in a field
  • Range - counts for a given set of ranges in a field
  • Histogram and Date Histogram - counts by constant interval ranges
  • Statistical - statistical summary of a field (mean, sum etc)
  • Terms Stats - statistical summary on one field (stats field) for distinct terms in another field. For example, spending stats per department or per region.
  • Geo Distance: counts by distance ranges from a given point
728x90
반응형