Skip to content

Instantly share code, notes, and snippets.

@neatlife
Last active September 22, 2017 09:10
Show Gist options
  • Save neatlife/b4bf3bbe349ef9fbcb0c9355e244bbc8 to your computer and use it in GitHub Desktop.
Save neatlife/b4bf3bbe349ef9fbcb0c9355e244bbc8 to your computer and use it in GitHub Desktop.
elasticsearch api学习
PUT /megacorp/employee/1
{
"first_name": "John",
"last_name": "Smith",
"age": 25,
"about": "I love to go rock climbing",
"interests": ["sports", "music"]
}
PUT /megacorp/employee/2
{
"first_name": "Jane",
"last_name": "Smith",
"age": 32,
"about": "I like to collect rock albums",
"interests": ["music"]
}
PUT /megacorp/employee/3
{
"first_name": "Douglas",
"last_name": "Fir",
"age": 35,
"about": "I like to build cabinets",
"interests": ["forestry"]
}
GET /megacorp/employee/1
HEAD /megacorp/employee/1
DELETE /megacorp/employee/1
GET /megacorp/employee/_search
GET /megacorp/employee/_search?q=last_name:Smith
GET /megacorp/employee/_search
{
"query": {
"match": {
"last_name": "Smith"
}
}
}
GET /megacorp/employee/_search
{
"query": {
"filtered": {
"filter": {
"range": {
"age": {"gt": 30}
}
},
"query": {
"match": {
"last_name": "smith"
}
}
}
}
}
GET /megacorp/employee/_search
{
"explain": true,
"query": {
"match": {
"about": "rock climbing"
}
}
}
GET /megacorp/employee/_search
{
"query": {
"match_phrase": {
"about": "rock climbing"
}
}
}
GET /megacorp/employee/_search
{
"query": {
"match_phrase": {
"about": "rock climbing"
}
},
"highlight": {
"fields": {
"about": {}
}
}
}
GET /megacorp/employee/_search
{
"aggs": {
"all_interests": {
"terms": {"field": "interests"}
}
}
}
GET /megacorp/employee/_search
{
"query": {
"match": {
"last_name": "Smith"
}
},
"aggs": {
"all_interests": {
"terms": {"field": "interests"}
}
}
}
GET /megacorp/employee/_search
{
"aggs": {
"all_interests": {
"terms": {"field": "interests"},
"aggs": {
"avg_age": {
"avg": {"field": "age"}
}
}
}
}
}
GET /_analyze?analyzer=standard&text=Text to analyze
GET /_analyze?analyzer=standard&text=中华人民共和国
GET /megacorp/_analyze?analyzer=ik_smart&text=中华人民共和国
GET /megacorp/_analyze?analyzer=ik_max_word&text=中华人民共和国
GET /megacorp/_analyze?analyzer=ik_max_word&text=%e4%b8%ad%e5%8d%8e%e4%ba%ba%e6%b0%91%e5%85%b1%e5%92%8c%e5%9b%bd%e5%9b%bd%e6%ad%8c
GET /gb/tweet/_search
GET /us/tweet/_search
GET /gb/_search
GET /_search
DELETE /megacorp
GET /_search?size=5&from=5
GET /_all/tweet/_search?q=tweet:elasticsearch
GET /_search?q=%2Bname%3Ajohn+%2Btweet%3Amary
GET /_search?q=mary
GET /_search?q=2014
GET /_search?q=2014-09-15
GET /_search?q=date:2014-09-15
GET /_search?q=date:2014
GET /gb/_mapping/tweet
GET /_analyze?analyzer=standard&text=Text to analyze
DELETE /gb
PUT /gb
{
"mappings": {
"tweet": {
"properties": {
"tweet": {
"type": "string",
"analyzer": "english"
},
"date": {
"type": "date"
},
"name": {
"type": "string"
},
"user_id": {
"type": "long"
}
}
}
}
}
PUT /gb/_mapping/tweet
{
"properties": {
"tag": {
"type": "string",
"index": "not_analyzed"
}
}
}
GET /gb/_analyze?field=tweet&text=Black-cats
GET /gb/_analyze?field=tag&text=Black-cats
PUT /alternative
{
"mappings": {
"software": {
"properties": {
"name": {
"type": "string",
"analyzer": "ik_max_word"
}
}
}
}
}
PUT /alternative/software/1
{
"name": "办公软件"
}
PUT /alternative/software/2
{
"name": "WPS2016下载_免费正版的办公软件"
}
PUT /alternative/software/3
{
"name": "科学,分科而学的意思,后指将各种知识通过细化分类(如数学、物理、化学等)研究,形成逐渐完整的知识体系。它是关于发现发明创造实践的学问,它是人类探索研究"
}
GET /alternative/software/_search
{
"query": {
"match": {
"name": "办公"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment