ES 简单命令 列举

GET _search
{"query":{"match_all":{}}}

PUT /megacorp/employee/1?pretty
{
    "first_name" : "John",
    "last_name" :  "Smith",
    "age" :        25,
    "about" :      "I love to go rock climbing",
    "interests": [ "sports", "music" ]
}


PUT /megacorp/employee/2?pretty
{
    "first_name" :  "Jane",
    "last_name" :   "Smith",
    "age" :         32,
    "about" :       "I like to collect rock albums",
    "interests":  [ "music" ]
}


PUT /megacorp/employee/3?pretty
{
    "first_name" :  "Douglas",
    "last_name" :   "Fir",
    "age" :         35,
    "about":        "I like to build cabinets",
    "interests":  [ "forestry" ]
}

GET /megacorp/employee/3?pretty



GET /megacorp/employee/_search?pretty



GET /megacorp/employee/_search?q=last_name:Smith&pretty




GET /megacorp/employee/_search?pretty
{
    "query" : {
        "match" : {
            "last_name" : "Smith"
        }
    }
}


GET /megacorp/employee/_search?pretty
{
    "query" : {
        "bool": {
            "must": {
                "match" : {
                    "last_name" : "smith" 
                }
            },
            "filter": {
                "range" : {
                    "age" : { "gt" : 30 } 
                }
            }
        }
    }
}


GET /megacorp/employee/_search?pretty
{
    "query" : {
        "match" : {
            "about" : "rock climbing"
        }
    }
}


GET /megacorp/employee/_search?pretty
{
    "query" : {
        "match_phrase" : {
            "about" : "rock climbing"
        }
    }
}

GET /megacorp/employee/_search?pretty
{
    "query" : {
        "match_phrase" : {
            "about" : "rock climbing"
        }
    },
    "highlight": {
        "fields" : {
            "about" : {}
        }
    }
}


PUT /megacorp/_mapping?pretty
{
  "properties": {
    "interests": { 
      "type":     "text",
      "fielddata": true
    }
  }
}



GET /megacorp/employee/_search?pretty
{
  "aggs": {
    "all_interests": {
      "terms": { "field": "interests" }
    }
  }
}


GET /megacorp/employee/_search?pretty
{
  "query": {
    "match": {
      "last_name": "smith"
    }
  },
  "aggs": {
    "all_interests": {
      "terms": {
        "field": "interests"
      }
    }
  }
}


GET /megacorp/employee/_search?pretty
{
    "aggs" : {
        "all_interests" : {
            "terms" : { "field" : "interests" },
            "aggs" : {
                "avg_age" : {
                    "avg" : { "field" : "age" }
                }
            }
        }
    }
}




你可能感兴趣的:(ES 简单命令 列举)