—— from《Elasticsearch: The Definitive Guide》
curl -XGET http://localhost:9200/_count?pretty -d '
{
"query":{
"match_all":{}
}
}'
curl -i -XGET http://localhost:9200/
curl -XPUT http://localhost:9200/megacorp/employee/1?pretty -d '
{
"first_name":"John",
"last_name":"Smith",
"age":25,
"about":"I love to go rock climbing",
"interests":["sports","music"]
}'
curl -XPUT http://localhost:9200/megacorp/employee/2?pretty -d '
{
"first_name":"Jane",
"last_name":"Smith",
"age":32,
"about":"I like to collect rock albums",
"interests":["music"]
}'
curl -XPUT http://localhost:9200/megacorp/employee/3?pretty -d '
{
"first_name":"Douglas",
"last_name":"Fir",
"age":35,
"about":"I like to build cabinets",
"interests":["forestry"]
}'
curl -XGET http://localhost:9200/megacorp/employee/1?pretty
curl -XGET http://localhost:9200/megacorp/employee/_search?pretty
curl -XGET http://localhost:9200/megacorp/employee/_search?q=last_name:Smith&pretty
curl -XGET http://localhost:9200/megacorp/employee/_search?pretty -d '
{
"query":{
"match":{
"last_name":"Smith"
}
}
}'
curl -XGET http://localhost:9200/megacorp/employee/_search?pretty -d '
{
"query":{
"filtered":{
"filter":{
"range":{
"age":{
"gt":30
}
}
},
"query":{
"match":{
"last_name":"smith"
}
}
}
}
}'
curl -XGET http://localhost:9200/megacorp/employee/_search?pretty -d '
{
"query":{
"match":{
"about":"rock climbing"
}
}
}'
curl -XGET http://localhost:9200/megacorp/employee/_search?pretty -d '
{
"query":{
"match_phrase":{
"about":"rock climbing"
}
}
}'
curl -XGET http://localhost:9200/megacorp/employee/_search?pretty -d '
{
"query":{
"match_phrase":{
"about":"rock climbing"
}
},
"highlight":{
"fields":{
"about":{}
}
}
}'
curl -XGET http://localhost:9200/megacorp/employee/_search?pretty -d '
{
"aggs":{
"all_interests":{
"terms":{
"field":"interests"
}
}
}
}'
curl -XGET http://localhost:9200/megacorp/employee/_search?pretty -d '
{
"query":{
"match":{
"last_name":"smith"
}
},
"aggs":{
"all_interests":{
"terms":{
"field":"interests"
}
}
}
}'
curl -XGET http://localhost:9200/megacorp/employee/_search?pretty -d '
{
"aggs":{
"all_interests":{
"terms":{
"field":"interests"
},
"aggs":{
"avg_age":{
"avg":{
"field":"age"
}
}
}
}
}
}'
curl -XGET http://localhost:9200/_cluster/health?pretty
curl -XPUT http://localhost:9200/blogs?pretty -d '
{
"number_of_shards":3,
"number_of_replicas":1
}'
curl -XPUT http://localhost:9200/blogs/_settings?pretty -d '
{
"number_of_replicas":2
}'
curl -XPUT http://localhost:9200/website/blog/123?pretty -d '
{
"title":"My first blog entry",
"text":"Just trying this out...",
"date":"2014/01/01"
}'
curl -XPOST http://localhost:9200/website/blog/?pretty -d '
{
"title":"My second blog entry",
"text":"Still trying this out...",
"date":"2014/01/01"
}'
curl -XGET http://localhost:9200/website/blog/123?pretty
curl -i -XGET http://localhost:9200/website/blog/124?pretty
curl -XGET http://localhost:9200/website/blog/123?pretty&_source=title,text
curl -XGET http://localhost:9200/website/blog/123/_source
curl -i -XHEAD http://localhost:9200/website/blog/123
curl -i -XHEAD http://localhost:9200/website/blog/124
curl -XPUT http://localhost:9200/website/blog/123?pretty -d '
{
"title":"My first blog entry",
"text":"I am starting to get the hang of this...",
"date":"2014/01/02"
}'
curl -XDELETE http://localhost:9200/website/blog/123?pretty
curl -XPUT http://localhost:9200/website/blog/1/_create?pretty -d '
{
"title":"My first blog entry",
"text":"Just trying this out..."
}'
curl -XGET http://localhost:9200/website/blog/1?pretty
curl -XPUT http://localhost:9200/website/blog/1?version=1&pretty -d '
{
"title":"My first blog entry",
"text":"starting to get the hang of this..."
}'
curl -XPUT http://localhost:9200/website/blog/2?version=5&version_type=external&pretty -d '
{
"title":"My first external blog entry",
"text":"Starting to get the hang of this..."
}'
curl -XPUT http://localhost:9200/website/blog/2?version=10&version_type=external&pretty -d '
{
"title":"My first external blog entry",
"text":"This is a piece of cake..."
}'
curl -XPOST http://localhost:9200/website/blog/1/_update?pretty -d '
{
"doc":{
"tags":["testing"],
"views":0
}
}'
curl -XPOST http://localhost:9200/website/blog/1/_update?pretty -d '
{
"script":"ctx._source.views+=1"
}'
curl -XPOST http://localhost:9200/website/blog/1/_update?pretty -d '
{
"script":"ctx._source.tags+=new_tag",
"params":{
"new_tag":"search"
}
}'
curl -XPOST http://localhost:9200/website/blog/1/_update?pretty -d '
{
"script":"ctx.op = ctx._source.views == count ? '"'"'delete'"'"' : '"'"'none'"'",
"params":{
"count":1
}
}'
curl -XPOST http://localhost:9200/website/pageviews/1/_update?pretty -d '
{
"script":"ctx._source.views+=1",
"upsert":{
"views":1
}
}'
curl -XPOST http://localhost:9200/website/pageviews/1/_update?pretty&retry_on_conflict=5 -d '
{
"script":"ctx._source.views+=1",
"upsert":{
"views":0
}
}'
curl -XGET http://localhost:9200/_mget?pretty -d '
{
"docs":[
{
"_index":"website",
"_type":"blog",
"_id":2
},
{
"_index":"website",
"_type":"pageviews",
"_id":1,
"_source":"views"
}
]
}'
curl -XGET http://localhost:9200/website/blog/_mget?pretty -d '
{
"docs":[
{
"_id":2
},
{
"_type":"pageviews",
"_id":1
}
]
}'
curl -XGET http://localhost:9200/website/blog/_mget?pretty -d '
{
"ids":["2","1"]
}'
curl -XPOST http://localhost:9200/_bulk?pretty -d '
{"delete":{"_index":"website","_type":"blog","_id":"123"}}
{"create":{"_index":"website","_type":"blog","_id":"123"}}
{"title":"My first blog post"}
{"index":{"_index":"website","_type":"blog"}}
{"title":"My second blog post"}
{"update":{"_index":"website","_type":"blog","_id":"123","_retry_on_conflict":3}}
{"doc":{"title":"My updated blog post"}}
'
curl -XPOST http://localhost:9200/_bulk?pretty -d '
{"create":{"_index":"website","_type":"blog","_id":"123"}}
{"title":"Cannot create - it already exists"}
{"index":{"_index":"website","_type":"blog","_id":"123"}}
{"title":"But we can update it"}
'
curl -XPOST http://localhost:9200/website/_bulk?pretty -d '
{"index":{"_type":"log"}}
{"event":"User logged in"}
'
curl -XPOST http://localhost:9200/website/log/_bulk?pretty -d '
{"index":{}}
{"event":"User logged in"}
{"index":{"_type":"blog"}}
{"title":"Overriding the default type"}
'
curl -XGET http://localhost:9200/_search\?pretty
curl -XGET http://localhost:9200/_search?pretty&size=10&from=10
curl -XGET http://localhost:9200/gb/_mapping/tweet
curl -XGET http://lcoalhost:9200/ikyxxs/_mapping/faq?pretty
curl -XFELETE http://localhost:9200/gb
curl -XPUT http://localhost:9200/gb?pretty -d '
{
"mappings":{
"tweet":{
"properties":{
"tweet":{
"type":"string",
"analyzer":"english"
},
"date":{
"type":"date"
},
"name":{
"type":"string"
},
"user_id":{
"type":"long"
}
}
}
}
}'
curl -XPUT http://localhost:9200/gb_mapping/tweeet -d '
{
"properties":{
"tag":{
"type":"string",
"index":"not_analyzed"
}
}
}'
curl -XGET http://localhost:9200/gb/_analyze?field=tweet&pretty -d '
Black-cats'
curl -XGET http://localhost:9200/gb/_analyze?field=tag?pretty -d '
Black-cats'
curl -XGET http://localhost:9200/_search?pretty -d '
{
"query":{
"match_all":{}
}
}'
curl -XGET http://localhost:9200/_search?pretty -d '
{
"query":{
"match":{
"tweet":"elasticsearch"
}
}
}'
curl -XGET http://localhost:9200/_search?pretty -d '
{
"query":{
"filtered":{
"query":{
"match_all":{}
},
"filter":{
"term":{
"folder":"inbox"
}
}
}
}
}'
curl -XGET http://localhost:9200/_search?pretty -d '
{
"query":{
"filtered":{
"filter":{
"bool":{
"must":{
"term":{
"folder":"inbox"
}
},
"must_not":{
"query":{
"match":{
"email":"urgent business proposal"
}
}
}
}
}
}
}
}'
curl -XGET http://localhost:9200/gb/tweet/_validate/query?pretty -d '
{
"query":{
"tweet":{
"match":"really powerful"
}
}
}'
curl -XGET http://localhost:9200/gb/tweet/_validate/query?explain&pretty -d '
{
"query":{
"tweet":{
"match":"really powerful"
}
}
}'
curl -XGET http://localhost:9200/_validate/query?explain&pretty -d '
{
"query":{
"match":{
"tweet":"really powerful"
}
}
}'
curl -XGET http://localhost:9200/_search?pretty -d '
{
"query":{
"filtered":{
"filter":{
"term":{
"user_id":1
}
}
}
}
}'
curl -XGET http://localhost:9200/_search?pretty -d '
{
"query":{
"filtered":{
"filter":{
"term":{
"user_id":1
}
}
}
},
"sort":{
"date":{
"order":"desc"
}
}
}'
curl -XGET http://localhost:9200/_search?pretty -d '
{
"query":{
"filtered":{
"query":{
"match":{
"tweet":"manage text search"
}
},
"filter":{
"term":{
"user_id":2
}
}
}
},
"sort":[
{
"date":{
"order":"desc"
}
},
{
"_score":{
"order":desc
}
}
]
}'
curl -XGET http://localhost:9200/_search?pretty&sort=date:desc&sort=_score&q=search
curl -XGET http://localhost:9200/_search?pretty -d '
{
"query":{
"match":{
"tweet":"elasticsearch"
}
},
"sort":"tweet.raw"
}'
curl -XGET http://localhost:9200/_search?pretty&explain -d '
{
"query":{
"match":{
"tweet":"honeymoon"
}
}
}'
curl -XGET http://localhost:9200/us/tweet/12/_explain -d '
{
"query":{
"filtered":{
"filter":{
"term":{
"user_id":2
}
},
"query":{
"match":{
"tweet":"honeymoon"
}
}
}
}
}'
curl -XGET http://localhost:9200/_search?pretty -d '
{
"from":90,
"size":10
}'
curl -XGET http://localhost:9200/_search?pretty&routing=user_1,user2
curl -XGET http://localhost:9200/_search?pretty&search_type=count
curl -XGET http://localhost:9200/old_index/_search?search_type=scan&scroll=1m -d '
{
"query":{
"match_all":{}
},
"size":1000
}'
curl -XDELETE http://localhost:9200/my_index
curl -XDELETE http://localhost:9200/index_one,index_two
curl -XDELETE http://localhost:9200/index_*
curl -XDELETE http://localhost:9200/_all
curl -XPUT http://localhost:9200/my_temp_index?pretty -d '
{
"settings":{
"number_of_shards": 1,
"number_of_replicas": 0
}
}'
curl -XPUT http://localhost:9200/my_temp_index/_settings?pretty -d '
{
"number_of_replicas": 1
}'
curl -XPUT http://localhost:9200/spanish_docs?pretty -d '
{
"settings":{
"analysis":{
"anlayzer":{
"es_std":{
"type":"standard",
"stopwords":"_spanish_"
}
}
}
}
}'
curl -XGET http://localhost:9200/spanish_docs/_analyze?pretty&analyzer=es_std -d '
El veloz zorro marron'
curl -XPUT http://localhost:9200/my_index?pretty -d '
{
"settings":{
"analysis":{
"char_filter":{
"&_to_and":{
"type":"mapping",
"mappings":["&=> and"]
}
},
"filter":{
"my_stopwords":{
"type":"stop",
"stopwords":["the","a"]
}
},
"analyzer":{
"my_analyzer":{
"type":"custom",
"char_filter":["html_strip", "&_to_end"],
"tokenizer":"standard",
"filter":["lowercase", "my_stopwords"]
}
}
}
}
}'
curl -XGET http://localhost:9200/my_index/_analyze?analyzer=my_analyzer?pretty -d '
The quick & brown fox'
curl -XPUT http://localhost:9200/my_index/_mapping/my_type?pretty -d '
{
"properties":{
"title":{
"type":"string",
"analyzer":"my_analyzer"
}
}
}'
curl -XGET http://localhost:9200/_seach?pretty -d '
{
"query":{
"match":{
"title":"The quick brown fox"
}
}
}'
curl -XGET http://localhost:9200/_search?pretty -d '
{
"query":{
"multi_match":{
"query":"The quick brown fox",
"fields":["blog_en.title", "blog_es.title"]
}
}
}'
curl -XPUT http://localhost:9200/my_index?prertty -d '
{
"mappings":{
"my_type":{
"_source":{
"ebable":false
}
}
}
}'
curl -XGET http://localhost:9200/_search?pretty -d '
{
"query":{
"match_all":{}
},
"_source":["title", "created"]
}'
curl -XGET http://localhost:9200/_search?pretty -d '
{
"match":{
"_all": "john smith marketing"
}
}'
curl -XPUT http://localhost:9200/my_index/_mapping/my_type?pretty -d '
{
"my_type":{
"_all": {
"enabled":false
}
}
}'
curl -XPUT http://localhost:9200/my_index/my_type/_mapping?pretty -d '
{
"my_type":{
"_all": {
"analyzer":"whitespace"
}
}
}'
curl -XPUT http://localhost:9200/my_index?pretty -d '
{
"mapping":{
"my_type":{
"_id":{
"path":"doc_id"
},
"properties":{
"doc_id":{
"type":"string",
"index":"not_analyzed"
}
}
}
}
}'
curl -XPOST http://localhost:9200/my_index/my_type?pretty -d '
{
"doc_id":"123"
}'
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于