Some example queries in elasticsearch


Create Index

PUT /ecommerce
{
}

GET /ecommerce/_search
{
“query”: {
“match_all”: {}
}
}

DELETE /ecommerce

GEt /_cat/indices?v
PUT /ecommerce
{
“mappings”: {
“product”: {
“properties”: {
“name”: {
“type”: “string”
},
“price”: {
“type”: “double”
},
“description”: {
“type”: “string”
},
“status”: {
“type”: “string”
},
“quantity”: {
“type”: “integer”
},
“categories”: {
“type”: “nested”,
“properties”: {
“name”: {
“type”: “string”
}
}
},
“tags”: {
“type”: “string”
}
}
}
}
}
PUT /ecommerce/product/1001
{
“name” : “Yii freamwork”,
“pricce” : 10.1,
“description” : “learn free yii freamwork”,
“status” : “active”,
“quantity” : 1,
“categories” : [
{
“name” : “software”
}
],
“tags” : [“yii 1”, “yii 2”, “yii 3”]
}

PUT /ecommerce/product/1002
{
“name” : “asp.net freamwork”,
“pricce” : 10.1,
“description” : “asp.netfreamwork”,
“status” : “active”,
“quantity” : 1,
“categories” : [
{
“name” : “software”
}
],
“tags” : [“asp.net 1”, “asp.net 2”, “asp.net 3”]
}
PUT /ecommerce/product/1003
{
“name” : “master freamwork”,
“pricce” : 10.1,
“description” : “master freamwork”,
“status” : “active”,
“quantity” : 1,
“categories” : [
{
“name” : “software”
}
],
“tags” : [“master 1”, “master 2”, “master 3”]
}
PUT /ecommerce/product/1004
{
“name” : “ios “,
“pricce” : 10.1,
“description” : “ios”,
“status” : “pending”,
“quantity” : 1,
“categories” : [
{
“name” : “software”
}
],
“tags” : [“ios 1”, “ios 2”, “ios 3″]
}

Get /ecommerce/product/1001

Get /ecommerce/product/1

Get ecommerce/product/_search?q=*
Get ecommerce/product/_search?q=name:master

get ecommerce/product/_search?q=name:(master AND freamwork)

get ecommerce/product/_search?q=name:(master OR asp.net)
get ecommerce/product/_search?q=(name:(master OR asp.net) OR status:pending)

get ecommerce/product/_search?q=name:+freamwork -asp.net
get ecommerce/product/_search?q=name:”master freamwork”

get ecommerce/product/_search?q=name:”freamwork master”

get /_analyze?analyzer=standard&text=master freamwork

delete /restaurants
PUT /restaurants
GET /restaurants/_search
GEt /_cat/indices?v
GET /restaurants/restaurant/_search?q=name:”Hot ‘N Tasty”

GET /restaurants/restaurant/hang-trong-2Up9Y6QIqRaPFPYN
GET /restaurants/restaurant/_search
GET /comments/comment/_search

GET /comments/comment/54a6576b25a8592636ab4391-32S3n35B2xq8OKxa
delete /comments/2

GET /comments/comment/_search
{
“query”: {
“query_string” : {
“default_field” : “createdBy.username”,
“query” : “createdBy.username=be.tino.5”
}
}
}

GET /comments/comment/_search
{
“query”: {
“bool”: {
“should”:
{
“match”: {
“createdBy.city”: “Hà Nội”
}
},
“must_not”: [
{
“match”: {
“dish.eatery.address.city”: “Hà Nội”
}
}
]
}
}
}
GET /comments/comment/_search
{
“query”: {
“bool”: {
“should”: [
{ “match”: { “caption”: “ăn đêm” }}
],
“must”: [
{
“match”: {
“dish.food.name”: “Tiết canh”
}
}
]
}
}
}
GET /restaurants/restaurant/_search

PUT /twitter/tweet/_mapping
{

“tweet” : {

“properties” : {

“locations” : {“type” : “geo_point”}

}

}

}
PUT /restaurants/restaurant/_mapping
{
“restaurant”: {
“properties”: {
“locations”: {
“type”: “geo_point”
}
}
}
}

GET /restaurants/restaurant/_search
{
“query”: {
“bool”: {
“must”: [
{ “match_all”: {

}}
],
“filter”: {
“geo_distance” : {
“distance” : “1km”,
“locations” : {
“lat” : 16.046381,
“lon” : 108.218250
}
}
}
}
}
}

 

 

 
PUT testautocomplete/settings
{
“settings”: {
“index”: {
“analysis”: {
“filter”: {
“stemmer”: {
“type”: “stemmer”,
“language”: “english”
},
“autocompleteFilter”: {
“max_shingle_size”: “5”,
“min_shingle_size”: “2”,
“type”: “shingle”
},
“stopwords”: {
“type”: “stop”,
“stopwords”: [
“_english

]
}
},
“analyzer”: {
“didYouMean”: {
“filter”: [
“lowercase”
],
“char_filter”: [
“html_strip”
],
“type”: “custom”,
“tokenizer”: “standard”
},
“autocomplete”: {
“filter”: [
“lowercase”,
“autocompleteFilter”
],
“char_filter”: [
“html_strip”
],
“type”: “custom”,
“tokenizer”: “standard”
},
“default”: {
“filter”: [
“lowercase”,
“stopwords”,
“stemmer”
],
“char_filter”: [
“html_strip”
],
“type”: “custom”,
“tokenizer”: “standard”
}
}
}
}
}
}
PUT testautocomplete/_settings
{
“index” : {
“number_of_replicas” : 4
}
}

POST testautocomplete/_close

PUT testautocomplete/_settings
{
“index” : {
“analysis”: {
“filter”: {
“stemmer”: {
“type”: “stemmer”,
“language”: “english”
},
“autocompleteFilter”: {
“max_shingle_size”: “5”,
“min_shingle_size”: “2”,
“type”: “shingle”
},
“stopwords”: {
}
}
}
}
}

POST testautocomplete/_open

Get testautocomplete/_settings
Get testautocomplete/_analyze?pretty&analyzer=autocomplete&text=Recommend%20questions%20get%20too%20fulfilled.%20He%20fact%20in%20we%20case%20miss%20sake.%20Entrance%20be%20throwing%20he%20do%20blessing%20up

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s