zoukankan      html  css  js  c++  java
  • elasticsearch 搜索提示DSL

    1,创建mapping:

    PUT /news_website { "mappings": { "news" : { "properties" : { "title" : { "type": "text", "analyzer": "ik_max_word", "fields": { "suggest" : { "type" : "completion", "analyzer": "ik_max_word" } } }, "content": { "type": "text", "analyzer": "ik_max_word" } } } } }

      2,向索引中写入数据

    PUT /news_website/news/1
    {
      "title": "大话西游电影",
      "content": "大话西游的电影时隔20年即将在2017年4月重映"
    }
    PUT /news_website/news/2
    {
      "title": "大话西游小说",
      "content": "某知名网络小说作家已经完成了大话西游同名小说的出版"
    }
    PUT /news_website/news/3
    {
      "title": "大话西游手游",
      "content": "网易游戏近日出品了大话西游经典IP的手游,正在火爆内测中"
    }
    
    
    3,suggest 查询

    GET
    /news_website/news/_search { "suggest":{ "suggest":{ "prefix":"大话西游", "completion":{ "field":"title.suggest" } } } }
    GET /forum/article/_search
    {
        "query": {
            "match_phrase": {
                "title": {
                    "query": "java spark",
                    "slop":  1
                }
            }
        }
    }
    
    
    GET /forum/article/_search
    {
      "query": {
        "match_phrase": {
          "content": {
            "query": "spark data",
            "slop": 3
          }
        }
      }
    }
    
    
    GET /forum/article/_search
    {
      "query": {
        "match_phrase": {
          "content": {
            "query": "data spark",
            "slop": 5
          }
        }
      }
    }
    #索引1的分片移动到索引2
    
    POST /_cluster/reroute
    {
      "commands": [
        {
          "move": {
            "index": "my_index_name",
            "shard": 0,
            "from_node": "node1",
            "to_node": "node2"
          }
        },
        {
          "allocate": {
            "index": "my_index_name",
            "shard": 1,
            "node": "node3"
          }
        }
      ]
    }
    #动态更新最小节点数。
    
    
    PUT /_cluster/settings
    {
      "persistent": {
        "discovery.zen.minimum_master_nodes": 3
      }
    }
    
    GET /forum/article/_search
    {
      "query": {
        "match_phrase": {
          "content": {
            "query": "java best",
            "slop": 15
          }
        }
      }
    }
    
    
    GET /books/_search
    {
      "query": {
        "constant_score": {
          "filter": {
            "range": {
              "price": {
                "gte": 20,
                "lt": 40
              }
            }
          }
        }
      }
    }
    
    
    
    GET /books/_search
    {
      "query": {
        "constant_score": {
          "filter": {
            "exists": {
              "field": "title"
            }
          }
        }
      }
    }
    
    GET /books/_search
    {
      "query": {
        "constant_score": {
          "filter": {
            "bool": {
              "should": [
                {
                  "range": {
                    "price": {
                      "gte": 20,
                      "lte": 40
                    }
                  }
                }
              ]
            }
          },
          "boost": 1.2
        }
      }
    }
    POST /books/_search
    {
      "query": {
        "match": {
          "title": "Java"
        }
      },
      "size": 2,
      "from": 0,
      "_source": [
        "title",
        "language",
        "author"
      ],
      "highlight": {
        "fields": {
          "title": {}
        }
      }
    }
    
    POST ik_index/ik_type/3
    {
      "title":"公路局正在治理解放大道路面积水问题"
    }
    
    GET ik_index/ik_type/_search
    {
      "query": {
        "match_phrase": {
          "title": "道路"
        }
      }
    }
    
    
    GET cars/_search
    
    
    
    
    
    GET ik_index/ik_type/_search
    {
      "profile": "true",
      "query": {
        "match_phrase": {
          "title.ik_my_max": "道路"
        }
      }
    }
    GET /_analyze
    {
      "analyzer": "ik_max_word", 
    "text":"公路局正在治理解放大道路面积水问题"
    }
    
    
    PUT /my_index
    {
        "settings": {
            "analysis": {
                "filter": {
                    "autocomplete_filter": { 
                        "type":     "edge_ngram",
                        "min_gram": 1,
                        "max_gram": 20
                    }
                },
                "analyzer": {
                    "autocomplete": {
                        "type":      "custom",
                        "tokenizer": "standard",
                        "filter": [
                            "lowercase",
                            "autocomplete_filter" 
                        ]
                    }
                }
            }
        }
    }
    
    GET /my_index/_analyze
    {
      "analyzer": "autocomplete",
      "text": "quick brown"
    }
    
    PUT /my_index/_mapping/my_type
    {
      "properties": {
          "title": {
              "type":     "string",
              "analyzer": "autocomplete",
              "search_analyzer": "standard"
          }
      }
    }
    
    
    
    
    GET /my_index/my_type/_search 
    {
      "query": {
        "match_phrase": {
          "title": "hello w"
        }
      }
    }
    
    PUT my_index
    {
      "mappings": {
        "my_type": {
          "properties": {
            "title": {
              "type": "keyword"
            }
          }
        }
      }
    }
    
    GET my_index/my_type/_search
    {
      "query": {
        "prefix": {
          "title": {
            "value": "C3"
          }
        }
      }
    }
    
    GET /forum/article/_search
    {
      "query": {
        "match_phrase": {
          "content": {
            "query": "spark data",
            "slop": 3
          }
        }
      }
    }GET /forum/article/_search
    {
        "query": {
            "match_phrase": {
                "title": {
                    "query": "java spark",
                    "slop":  1
                }
            }
        }
    }
    
    
    POST /forum/article/5/_update
    {
      "doc": {
        "content": "spark is best big data solution based on scala ,an programming language similar to java spark"
      }
    }
    
    GET _analyze
    {
      "text": "hello world, java spark",
      "analyzer": "standard"
    }
    
    PUT /forum/_mapping/article
    {
      "properties": {
          "new_author_first_name": {
              "type":     "string",
              "copy_to":  "new_author_full_name" 
          },
          "new_author_last_name": {
              "type":     "string",
              "copy_to":  "new_author_full_name" 
          },
          "new_author_full_name": {
              "type":     "string"
          }
      }
    }
    
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"new_author_first_name" : "Peter", "new_author_last_name" : "Smith"} }        --> Peter Smith
    { "update": { "_id": "2"} }    
    { "doc" : {"new_author_first_name" : "Smith", "new_author_last_name" : "Williams"} }        --> Smith Williams
    { "update": { "_id": "3"} }
    { "doc" : {"new_author_first_name" : "Jack", "new_author_last_name" : "Ma"} }            --> Jack Ma
    { "update": { "_id": "4"} }
    { "doc" : {"new_author_first_name" : "Robbin", "new_author_last_name" : "Li"} }            --> Robbin Li
    { "update": { "_id": "5"} }
    { "doc" : {"new_author_first_name" : "Tonny", "new_author_last_name" : "Peter Smith"} }        --> Tonny Peter Smith
    
    GET /forum/article/_search
    {
      "query": {
        "match": {
          "new_author_full_name":       "Peter Smith"
        }
      }
    }
    
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"author_first_name" : "Peter", "author_last_name" : "Smith"} }
    { "update": { "_id": "2"} }
    { "doc" : {"author_first_name" : "Smith", "author_last_name" : "Williams"} }
    { "update": { "_id": "3"} }
    { "doc" : {"author_first_name" : "Jack", "author_last_name" : "Ma"} }
    { "update": { "_id": "4"} }
    { "doc" : {"author_first_name" : "Robbin", "author_last_name" : "Li"} }
    { "update": { "_id": "5"} }
    { "doc" : {"author_first_name" : "Tonny", "author_last_name" : "Peter Smith"} }
    
    GET /forum/article/_search
    {
      "query": {
        "multi_match": {
          "query":       "Peter Smith",
          "type":        "most_fields",
          "fields":      [ "author_first_name", "author_last_name" ]
        }
      }
    }
    POST /forum/_mapping/article
    {
      "properties": {
          "sub_title": { 
              "type":     "string",
              "analyzer": "english",
              "fields": {
                  "std":   { 
                      "type":     "string",
                      "analyzer": "standard"
                  }
              }
          }
      }
    }
    
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"sub_title" : "learning more courses"} }
    { "update": { "_id": "2"} }
    { "doc" : {"sub_title" : "learned a lot of course"} }
    { "update": { "_id": "3"} }
    { "doc" : {"sub_title" : "we have a lot of fun"} }
    { "update": { "_id": "4"} }
    { "doc" : {"sub_title" : "both of them are good"} }
    { "update": { "_id": "5"} }
    { "doc" : {"sub_title" : "haha, hello world"} }
    
    GET /forum/article/_search
    {
      "query": {
        "match": {
          "sub_title": "learning courses"
        }
      }
    }
    GET /forum/article/_search
    {
       "query": {
            "match": {
                "sub_title": "learning courses"
            }
        }
    }
    
    
    GET /forum/article/_search
    {
        "query": {
            "dis_max": {
                "queries": [
                    { "match": { "title": "java beginner" }},
                    { "match": { "body":  "java beginner" }}
                ]
            }
        }
    }
    GET /forum/article/_search
    {
        "query": {
            "dis_max": {
                "queries": [
                    { "match": { "title": "java beginner" }},
                    { "match": { "body":  "java beginner" }}
                ],
                "tie_breaker": 0.3
            }
        }
    }
    
    
    
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"content" : "i like to write best elasticsearch article"} }
    { "update": { "_id": "2"} }
    { "doc" : {"content" : "i think java is the best programming language"} }
    { "update": { "_id": "3"} }
    { "doc" : {"content" : "i am only an elasticsearch beginner"} }
    { "update": { "_id": "4"} }
    { "doc" : {"content" : "elasticsearch and hadoop are all very good solution, i am a beginner"} }
    { "update": { "_id": "5"} }
    { "doc" : {"content" : "spark is best big data solution based on scala ,an programming language similar to java"} }
    GET /forum/article/_search
    {
        "query": {
            "bool": {
                "should": [
                    { "match": { "title": "java solution" }},
                    { "match": { "content":  "java solution" }}
                ]
            }
        }
    }
    GET /forum/article/_search
    {
        "query": {
            "dis_max": {
                "queries": [
                    { "match": { "title": "java solution" }},
                    { "match": { "content":  "java solution" }}
                ]
            }
        }
    }
    
    GET /forum/article/_search 
    {
      "query": {
        "bool": {
          "must": [
            {
              "match": {
                "title": "blog"
              }
            }
          ],
          "should": [
            {
              "match": {
                "title": {
                  "query": "java"
                }
              }
            },
            {
              "match": {
                "title": {
                  "query": "hadoop"
                }
              }
            },
            {
              "match": {
                "title": {
                  "query": "elasticsearch"
                }
              }
            },
            {
              "match": {
                "title": {
                  "query": "spark",
                  "boost": 5
                }
              }
            }
          ]
        }
      }
    }
    
    
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"title" : "this is java and elasticsearch blog"} }
    { "update": { "_id": "2"} }
    { "doc" : {"title" : "this is java blog"} }
    { "update": { "_id": "3"} }
    { "doc" : {"title" : "this is elasticsearch blog"} }
    { "update": { "_id": "4"} }
    { "doc" : {"title" : "this is java, elasticsearch, hadoop blog"} }
    { "update": { "_id": "5"} }
    { "doc" : {"title" : "this is spark blog"} }
    
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"title" : "this is java and elasticsearch blog"} }
    { "update": { "_id": "2"} }
    { "doc" : {"title" : "this is java blog"} }
    { "update": { "_id": "3"} }
    { "doc" : {"title" : "this is elasticsearch blog"} }
    { "update": { "_id": "4"} }
    { "doc" : {"title" : "this is java, elasticsearch, hadoop blog"} }
    { "update": { "_id": "5"} }
    { "doc" : {"title" : "this is spark blog"} }
    GET /forum/article/_search
    {
        "query": {
            "match": {
                "title": {
            "query": "java elasticsearch",
            "operator": "and"
               }
            }
        }
    }
    GET /forum/article/_search
    {
        "query": {
            "match": {
                "title": {
            "query": "java elasticsearch",
            "operator": "and"
               }
            }
        }
    }
    GET /forum/article/_search
    {
      "query": {
        "bool": {
          "must":     { "match": { "title": "java" }},
          "must_not": { "match": { "title": "spark"  }},
          "should": [
                      { "match": { "title": "hadoop" }},
                      { "match": { "title": "elasticsearch"   }}
          ]
        }
      }
    }
    GET /forum/article/_search
    {
      "query": {
        "bool": {
          "should": [
            { "match": { "title": "java" }},
            { "match": { "title": "elasticsearch"   }},
            { "match": { "title": "hadoop"   }},
        { "match": { "title": "spark"   }}
          ],
          "minimum_should_match": 3 
        }
      }
    }
    GET /books/_search
    {
      "size": 0,
      "aggs": {
        "grades_stats": {
          "stats": {
            "field": "price"
          }
        }
      }
    }
    
    
    
    GET /_search
    {
      "query": {
        "bool": {
          "should": [
            { "match": { "address": "mill" } },
            { "match": { "address": "lane" } }
          ]
        }
      }
    }
    
    
    PUT my_index/my_type/1
    {
      "full_text":   "Quick Foxes!", 
      "exact_value": "Quick Foxes!"  
    }
    
    
    GET my_index/my_type/_search
    {
      "query": {
        "term": {
          "exact_value": "Quick Foxes!" 
        }
      }
    }
    
    GET my_index/my_type/_search
    {
      "query": {
        "term": {
          "full_text": "Quick Foxes!" 
        }
      }
    }
    GET my_index/my_type/_search
    {
      "query": {
        "term": {
          "full_text": "foxes" 
        }
      }
    }
    
    GET my_index/my_type/_search
    {
      "query": {
        "match": {
          "full_text": "Quick Foxes!" 
        }
      }
    }
    
    
    
    
    
    POST /termtest/termtype/1
    {
      "content":"Name"
    }
    
    POST /termtest/termtype/2
    {
      "content":"name city"
    }
    
    GET /termtest/_search
    {
      "query":
      {
        "match_all": {}
      }
    }
    
    POST /termtest/_search
    {
      "query":{
        "term":{
          "content":"name"
        }
      }
    }
    
    POST /termtest/_search
    {
      "query":{
        "match":{
          "content":"Name"
        }
      }
    }
    
    
    
    
    
    
    
    
    
    PUT my_index/my_type/2
    {
     "zuMaker":
        {"type":"keyword","index":"false"}
    
    }
    
    PUT my_index/my_type/3
    {
    "zuName":
           {"type":"text","index":"true","boost":"5","analyzer":"ik_max_word","search_analyzer":"ik_max_word"}
    
    
    }
    
    
    
    
    
    
    PUT my_index/my_type/2
    {
     "zuMaker":
        {"type":"keyword","index":"false"}
    
    }
    
    PUT my_index/my_type/3
    {
    "zuName":
           {"type":"text","index":"true","boost":"5","analyzer":"ik_max_word","search_analyzer":"ik_max_word"}
    
    
    }
    
    
    GET my_index/my_type/_search
    
     { "query": { "term": { "zuName": "墙体钢结构" } } }
    
    GET my_index/my_type/_search
    { "query": { "term": { "zuMakert": "张三李四" } } }
    
    GET my_index/my_type/_search
    
    
    PUT my_index/my_type/2
    {
     "zuMaker":
      {
      "type": "keyword",
      "index": "false",
      "content":"张三李四"
    }
    
    }
    
    PUT my_index/my_type/3
    {
      "zuName": {
        "type": "text",
        "index": "true",
        "boost": "5",
        "analyzer": "ik_max_word",
        "search_analyzer": "ik_max_word",
         "content":"墙体钢结构"
      }
    }
    GET my_index/_search
    
            { "query": { "term": { "zuMakert": "张三李四" } } }
    
    
    //设置mapping
    POST /productindex/product/_mapping?pretty
    {
        "product": {
                "properties": {
                    "title": {
                        "type": "string",
                        "store": "yes"
                    },
                    "description": {
                        "type": "string",
                        "index": "not_analyzed"
                    },
                    "price": {
                        "type": "double"
                    },
                    "onSale": {
                        "type": "boolean"
                    },
                    "type": {
                        "type": "integer"
                    },
                    "createDate": {
                        "type": "date"
                    }
                }
            }
      }
    
    //新增mapping
    POST /productindex/product/_mapping?pretty
    {
         "product": {
                    "properties": {
                         "amount":{
                            "type":"integer"
                       }
                    }
                }
        }
    
    POST /productindex/product/_mapping?pretty
    {
         "product": {
                    "properties": {
                     "onSale":{
                        "type":"string" 
                   }
                }
            }
    }
    
    
    //设置mapping之后,插入数据
    POST /productindex/product/1
    {
        "title" : "John",
        "description" :  "Smith",
        "price" :        25,
        "onSale" :  ""  ,
        "type": 1,
        "createDate" : "2017-08-26"
    }
    
    
    //精确查找
    
    GET /test_index2/_search
    {
      "query": {
        "match_phrase": {
          "title":"Java程序性能优化"
        }
      }
    }
    
    
    //如果我们希望两个字段进行匹配,其中一个字段有这个文档就满足的话,使用multi_match
    
    GET /test_index2/_search
    {
      "query": {
        "multi_match": {
           "query" : "Java程序性能优化",
          "fields" : ["title", "language"]
        }
      }
    }
    
    
    //boolean 查询
    
    GET /test_index2/_search
    {
      "query": {
        "bool": {
          "must": {
            "term": {
              "title": "java"
            }
          },
          "must_not": {
            "term": {
              "language": "javascript"
            }
          }
        }
      }
    }
    
    
    //and  or 查询
    
    
    GET /test_index2/_search
    {
        "query": {
            "match": {
                "title": {      
                   "query":    "Java Python",
                    "operator": "or"   --and
                }
            }
        }
    }
    
    
    
    
    //range 过滤
    
    GET /_search
    {
      "query": {
        "range": {
          "age": {
            "gte": 25,
            "lt": 30
          }
        }
      }
    }
    
    #The filtered query has been deprecated and removed in ES 5.0. You should now use the bool/must/filter query instead.
    
    {
        "query": {
            "bool": {
                "must": {
                    "multi_match": {
                        "operator": "and",
                        "fields": [
                            "author",
                            "title",
                            "publisher",
                            "year"
                        ],
                        "query": "George Orwell"
                    }
                },
                "filter": {
                    "terms": {
                        "year": [
                            1980,
                            1981
                        ]
                    }
                }
            }
        }
    }
    PUT /artists/
    {
      "settings": {
        "analysis": {
          "analyzer": {
            "user_name_analyzer": {
              "tokenizer": "whitespace",
              "filter": "pinyin_first_letter_and_full_pinyin_filter"
            }
          },
          "filter": {
            "pinyin_first_letter_and_full_pinyin_filter": {
              "type": "pinyin",
              "keep_first_letter": true,
              "keep_full_pinyin": false,
              "keep_none_chinese": true,
              "keep_original": false,
              "limit_first_letter_length": 16,
              "lowercase": true,
              "trim_whitespace": true,
              "keep_none_chinese_in_first_letter": true
            }
          }
        }
      }
    }
    
    GET /artists/_analyze
    {
      "text": ["刘德华 张学友 郭富城 黎明 王传付  四大天王"],
      "analyzer": "user_name_analyzer"
    }
    
    
    #查询指定条件的数据
    #select  * from order o where o.price=20
     GET /my_store/_search
    {
      "query": {
        "bool": {
          "must": {
            "match_all": {
             
            }
          },
          "filter": {
            "term": {
              "price" : 20
            }
          }
        }
      }
    }
    
    
    
    
    PUT /website 
    {
      "mappings": {
        "article": {
          "properties": {
            "title": {
              "type": "text",
              "fields": {
                "raw": {
                  "type": "string",
                  "index": "not_analyzed"
                }
              },
              "fielddata": true
            },
            "content": {
              "type": "text"
            },
            "post_date": {
              "type": "date"
            },
            "author_id": {
              "type": "long"
            }
          }
        }
      }
    }
    
    PUT /website/article/1
    {
      "title": "first article",
      "content": "this is my second article",
      "post_date": "2017-01-01",
      "author_id": 110
    }
    
    {
      "took": 2,
      "timed_out": false,
      "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
      },
      "hits": {
        "total": 3,
        "max_score": 1,
        "hits": [
          {
            "_index": "website",
            "_type": "article",
            "_id": "2",
            "_score": 1,
            "_source": {
              "title": "first article",
              "content": "this is my first article",
              "post_date": "2017-02-01",
              "author_id": 110
            }
          },
          {
            "_index": "website",
            "_type": "article",
            "_id": "1",
            "_score": 1,
            "_source": {
              "title": "second article",
              "content": "this is my second article",
              "post_date": "2017-01-01",
              "author_id": 110
            }
          },
          {
            "_index": "website",
            "_type": "article",
            "_id": "3",
            "_score": 1,
            "_source": {
              "title": "third article",
              "content": "this is my third article",
              "post_date": "2017-03-01",
              "author_id": 110
            }
          }
        ]
      }
    }
    
    GET /website/article/_search
    {
      "query": {
        "match_all": {}
      },
      "sort": [
        {
          "title.raw": {
            "order": "desc"
          }
        }
      ]
    }
    
    
    
    
    GET /_search
    {
        "query" : {
            "bool" : {
                "filter" : {
                    "term" : {
                        "author_id" : 1
                    }
                }
            }
        }
    }
    
    当然,也可以是constant_score
    
    GET /_search
    {
        "query" : {
            "constant_score" : {
                "filter" : {
                    "term" : {
                        "author_id" : 1
                    }
                }
            }
        }
    }
    
    2、定制排序规则
    
    GET /company/employee/_search 
    {
      "query": {
        "constant_score": {
          "filter": {
            "range": {
              "age": {
                "gte": 30
              }
            }
          }
        }
      },
      "sort": [
        {
          "join_date": {
            "order": "asc"
          }
        }
      ]
    }
    
    
    
    
    
    
    GET /website/article/_search
    {
      "query": {
        "bool": {
          "must": [
            {
              "match": {
                "title": "elasticsearch"
              }
            }
          ],
          "should": [
            {
              "match": {
                "content": "elasticsearch"
              }
            }
          ],
          "must_not": [
            {
              "match": {
                "author_id": 111
              }
            }
          ]
        }
      }
    }
    
    GET /test_index/_search
    {
        "query": {
                "bool": {
                    "must": { "match":   { "name": "tom" }},
                    "should": [
                        { "match":       { "hired": true }},
                        { "bool": {
                            "must":      { "match": { "personality": "good" }},
                            "must_not":  { "match": { "rude": true }}
                        }}
                    ],
                    "minimum_should_match": 1
                }
        }
    }
    
    
    
    
    
    1、match all
    
    GET /_search
    {
        "query": {
            "match_all": {}
        }
    }
    
    2、match
    
    GET /_search
    {
        "query": { "match": { "title": "my elasticsearch article" }}
    }
    
    3、multi match
    
    GET /test_index/test_type/_search
    {
      "query": {
        "multi_match": {
          "query": "test",
          "fields": ["test_field", "test_field1"]
        }
      }
    }
    
    4、range query
    
    GET /company/employee/_search 
    {
      "query": {
        "range": {
          "age": {
            "gte": 30
          }
        }
      }
    }
    
    5、term query
    
    GET /test_index/test_type/_search 
    {
      "query": {
        "term": {
          "test_field": "test hello"
        }
      }
    }
    
    6、terms query
    
    GET /_search
    {
        "query": { "terms": { "tag": [ "search", "full_text", "nosql" ] }}
    }
    PUT /company/employee/2
    {
      "address": {
        "country": "china",
        "province": "jiangsu",
        "city": "nanjing"
      },
      "name": "tom",
      "age": 30,
      "join_date": "2016-01-01"
    }
    
    PUT /company/employee/3
    {
      "address": {
        "country": "china",
        "province": "shanxi",
        "city": "xian"
      },
      "name": "marry",
      "age": 35,
      "join_date": "2015-01-01"
    }
    
    GET /company/employee/_search
    {
      "query": {
        "bool": {
          "must": [
            {
              "match": {
                "join_date": "2016-01-01"
              }
            }
          ],
          "filter": {
            "range": {
              "age": {
                "gte": 30
              }
            }
          }
        }
      }
    }
    
    
    2、修改mapping
    
    只能创建index时手动建立mapping,或者新增field mapping,但是不能update field mapping
    
    PUT /website
    {
      "mappings": {
        "article": {
          "properties": {
            "author_id": {
              "type": "long"
            },
            "title": {
              "type": "text",
              "analyzer": "english"
            },
            "content": {
              "type": "text"
            },
            "post_date": {
              "type": "date"
            },
            "publisher_id": {
              "type": "text",
              "index": "not_analyzed"
            }
          }
        }
      }
    }
    
    PUT /website
    {
      "mappings": {
        "article": {
          "properties": {
            "author_id": {
              "type": "text"
            }
          }
        }
      }
    }
    
    {
      "error": {
        "root_cause": [
          {
            "type": "index_already_exists_exception",
            "reason": "index [website/co1dgJ-uTYGBEEOOL8GsQQ] already exists",
            "index_uuid": "co1dgJ-uTYGBEEOOL8GsQQ",
            "index": "website"
          }
        ],
        "type": "index_already_exists_exception",
        "reason": "index [website/co1dgJ-uTYGBEEOOL8GsQQ] already exists",
        "index_uuid": "co1dgJ-uTYGBEEOOL8GsQQ",
        "index": "website"
      },
      "status": 400
    }
    
    PUT /website/_mapping/article
    {
      "properties" : {
        "new_field" : {
          "type" :    "string",
          "index":    "not_analyzed"
        }
      }
    }
    
    GET /website/_mapping
    3、测试mapping
    
    GET /website/_analyze
    {
      "field": "content",
      "text": "my-dogs" 
    }
    
    GET website/_analyze
    {
      "field": "new_field",
      "text": "my dogs"
    }
    
    {
      "error": {
        "root_cause": [
          {
            "type": "remote_transport_exception",
            "reason": "[4onsTYV][127.0.0.1:9300][indices:admin/analyze[s]]"
          }
        ],
        "type": "illegal_argument_exception",
        "reason": "Can't process field [new_field], Analysis requests are only supported on tokenized fields"
      },
      "status": 400
    }
    
    PUT /website/article/1
    {
      "post_date": "2017-01-01",
      "title": "my first article",
      "content": "this is my first article in this website",
      "author_id": 11400
    }
    
    PUT /website/article/2
    {
      "post_date": "2017-01-02",
      "title": "my second article",
      "content": "this is my second article in this website",
      "author_id": 11400
    }
    
    PUT /website/article/3
    {
      "post_date": "2017-01-03",
      "title": "my third article",
      "content": "this is my third article in this website",
      "author_id": 11400
    }
    
    尝试各种搜索
    
    GET /website/_mapping/article
    
    {
      "website": {
        "mappings": {
          "article": {
            "properties": {
              "author_id": {
                "type": "long"
              },
              "content": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "post_date": {
                "type": "date"
              },
              "title": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              }
            }
          }
        }
      }
    }
    
    GET /_search
    
    {
      "took": 6,
      "timed_out": false,
      "_shards": {
        "total": 6,
        "successful": 6,
        "failed": 0
      },
      "hits": {
        "total": 10,
        "max_score": 1,
        "hits": [
          {
            "_index": ".kibana",
            "_type": "config",
            "_id": "5.2.0",
            "_score": 1,
            "_source": {
              "buildNum": 14695
            }
          }
        ]
      }
    }
    #bulk语法
    
    POST /_bulk
    { "delete": { "_index": "test_index", "_type": "test_type", "_id": "3" }} 
    { "create": { "_index": "test_index", "_type": "test_type", "_id": "12" }}
    { "test_field":    "test12" }
    { "index":  { "_index": "test_index", "_type": "test_type", "_id": "2" }}
    { "test_field":    "replaced test2" }
    { "update": { "_index": "test_index", "_type": "test_type", "_id": "1", "_retry_on_conflict" : 3} }
    { "doc" : {"test_field2" : "bulk test1"} }
    
    POST /test_index/_bulk
    { "delete": { "_type": "test_type", "_id": "3" }} 
    { "create": { "_type": "test_type", "_id": "12" }}
    { "test_field":    "test12" }
    { "index":  { "_type": "test_type" }}
    { "test_field":    "auto-generate id test" }
    { "index":  { "_type": "test_type", "_id": "2" }}
    { "test_field":    "replaced test2" }
    { "update": { "_type": "test_type", "_id": "1", "_retry_on_conflict" : 3} }
    { "doc" : {"test_field2" : "bulk test1"} }
    
    POST /test_index/test_type/_bulk
    { "delete": { "_id": "3" }} 
    { "create": { "_id": "12" }}
    { "test_field":    "test12" }
    { "index":  { }}
    { "test_field":    "auto-generate id test" }
    { "index":  { "_id": "2" }}
    { "test_field":    "replaced test2" }
    { "update": { "_id": "1", "_retry_on_conflict" : 3} }
    { "doc" : {"test_field2" : "bulk test1"} }
    
    
    GET /_mget
    {
       "docs" : [
          {
             "_index" : "test_index",
             "_type" :  "test_type",
             "_id" :    1
          },
          {
             "_index" : "test_index",
             "_type" :  "test_type",
             "_id" :    2
          }
       ]
    }
    
    {
      "docs": [
        {
          "_index": "test_index",
          "_type": "test_type",
          "_id": "1",
          "_version": 2,
          "found": true,
          "_source": {
            "test_field1": "test field1",
            "test_field2": "test field2"
          }
        },
        {
          "_index": "test_index",
          "_type": "test_type",
          "_id": "2",
          "_version": 1,
          "found": true,
          "_source": {
            "test_content": "my test"
          }
        }
      ]
    }
    
    (3)如果查询的document是一个index下的不同type种的话
    
    GET /test_index/_mget
    {
       "docs" : [
          {
             "_type" :  "test_type",
             "_id" :    1
          },
          {
             "_type" :  "test_type",
             "_id" :    2
          }
       ]
    }
    
    (4)如果查询的数据都在同一个index下的同一个type下,最简单了
    
    GET /test_index/test_type/_mget
    {
       "ids": [1, 2]
    }
    
    
    PUT /test_index/test_type/11
    {
      "num": 0,
      "tags": []
    }
    POST /test_index/test_type/11/_update
    {
       "script" : "ctx._source.num+=1"
    }
    
    {
      "_index": "test_index",
      "_type": "test_type",
      "_id": "11",
      "_version": 2,
      "found": true,
      "_source": {
        "num": 1,
        "tags": []
      }
    }
    
    
    POST /test_index/test_type/11/_update
    {
      "script": {
        "lang": "groovy", 
        "file": "test-add-tags",
        "params": {
          "new_tag": "tag1"
        }
      }
    }
    POST /test_index/test_type/11/_update
    {
      "doc": {
        "num": 1
      }
    }
    GET /ecommerce/product/_search
    {
      "aggs": {
        "group_by_tags": {
          "terms": { "field": "tags" }
        }
      }
    }
    
    GET /car/_search
    
    GET /car/_search
    {
      "aggs": {
        "group_by_color": {
          "terms": { "field": "color" }
        }
      }
    }
    PUT /ecommerce/_mapping/product
    {
      "properties": {
        "tags": {
          "type": "text",
          "fielddata": true
        }
      }
    }
    GET /ecommerce/product/_search
    {
      "size": 0,
      "aggs": {
        "all_tags": {
          "terms": { "field": "tags" }
        }
      }
    }
    GET /ecommerce/product/_search
    {
      "size": 0,
      "query": {
        "match": {
          "name": "yagao"
        }
      },
      "aggs": {
        "all_tags": {
          "terms": {
            "field": "tags"
          }
        }
      }
    }
    GET /ecommerce/product/_search
    {
        "size": 0,
        "aggs" : {
            "group_by_tags" : {
                "terms" : { "field" : "tags" },
                "aggs" : {
                    "avg_price" : {
                        "avg" : { "field" : "price" }
                    }
                }
            }
        }
    }
    
    
    GET /ecommerce/product/_search
    {
        "size": 0,
        "aggs" : {
            "all_tags" : {
                "terms" : { "field" : "tags", "order": { "avg_price": "desc" } },
                "aggs" : {
                    "avg_price" : {
                        "avg" : { "field" : "price" }
                    }
                }
            }
        }
    }
    
    GET /ecommerce/product/_search
    {
      "size": 0,
      "aggs": {
        "group_by_price": {
          "range": {
            "field": "price",
            "ranges": [
              {
                "from": 0,
                "to": 20
              },
              {
                "from": 20,
                "to": 40
              },
              {
                "from": 40,
                "to": 50
              }
            ]
          },
          "aggs": {
            "group_by_tags": {
              "terms": {
                "field": "tags"
              },
              "aggs": {
                "average_price": {
                  "avg": {
                    "field": "price"
                  }
                }
              }
            }
          }
        }
      }
    }
    GET /ecommerce/product/_search
    {
      "query": { "match_all": {} }
    }
    
    
    
    GET /ecommerce/product/_search
    {
        "query" : {
            "match" : {
                "name" : "yagao"
            }
        },
        "sort": [
            { "price": "desc" }
        ]
    }
    GET /ecommerce/product/_search
    {
      "query": { "match_all": {} },
      "from": 1,
      "size": 1
    }
    GET /ecommerce/product/_search
    {
      "query": { "match_all": {} },
      "_source": ["name", "price"]
    }
    
    GET /ecommerce/product/_search
    {
        "query" : {
            "bool" : {
                "must" : {
                    "match" : {
                        "name" : "yagao" 
                    }
                },
                "filter" : {
                    "range" : {
                        "price" : { "gt" : 25 } 
                    }
                }
            }
        }
    }
    
    GET /ecommerce/product/_search
    {
        "query" : {
            "match" : {
                "producer" : "yagao producer"
            }
        }
    }
    GET /ecommerce/product/_search
    {
        "query" : {
            "match_phrase" : {
                "producer" : "yagao producer"
            }
        }
    }
    GET /ecommerce/product/_search
    {
        "query" : {
            "match" : {
                "producer" : "producer"
            }
        },
        "highlight": {
            "fields" : {
                "producer" : {}
            }
        }
    }
    POST /forum/article/_bulk
    { "index": { "_id": 1 }}
    { "articleID" : "XHDK-A-1293-#fJ3", "userID" : 1, "hidden": false, "postDate": "2017-01-01" }
    { "index": { "_id": 2 }}
    { "articleID" : "KDKE-B-9947-#kL5", "userID" : 1, "hidden": false, "postDate": "2017-01-02" }
    { "index": { "_id": 3 }}
    { "articleID" : "JODL-X-1937-#pV7", "userID" : 2, "hidden": false, "postDate": "2017-01-01" }
    { "index": { "_id": 4 }}
    { "articleID" : "QQPX-R-3956-#aD8", "userID" : 2, "hidden": true, "postDate": "2017-01-02" }
    
    
    
    
    
    GET /forum/_mapping/article
    
    {
      "forum": {
        "mappings": {
          "article": {
            "properties": {
              "articleID": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "hidden": {
                "type": "boolean"
              },
              "postDate": {
                "type": "date"
              },
              "userID": {
                "type": "long"
              }
            }
          }
        }
      }
    }
    GET /forum/article/_search
    {
        "query" : {
            "constant_score" : { 
                "filter" : {
                    "term" : { 
                        "userID" : 1
                    }
                }
            }
        }
    }
    
    GET /forum/article/_search
    {
        "query" : {
            "constant_score" : { 
                "filter" : {
                    "term" : { 
                        "hidden" : false
                    }
                }
            }
        }
    }
    GET /forum/article/_search
    {
        "query" : {
            "constant_score" : { 
                "filter" : {
                    "term" : { 
                        "postDate" : "2017-01-01"
                    }
                }
            }
        }
    }
    
    GET /forum/article/_search
    {
        "query" : {
            "constant_score" : { 
                "filter" : {
                    "term" : { 
                        "articleID" : "XHDK-A-1293-#fJ3"
                    }
                }
            }
        }
    }
    GET /forum/_analyze
    {
      "field": "articleID",
      "text": "XHDK-A-1293-#fJ3"
    }
    
    DELETE /forum
    
    PUT /forum
    {
      "mappings": {
        "article": {
          "properties": {
            "articleID": {
              "type": "keyword"
            }
          }
        }
      }
    }
    
    POST /forum/article/_bulk
    { "index": { "_id": 1 }}
    { "articleID" : "XHDK-A-1293-#fJ3", "userID" : 1, "hidden": false, "postDate": "2017-01-01" }
    { "index": { "_id": 2 }}
    { "articleID" : "KDKE-B-9947-#kL5", "userID" : 1, "hidden": false, "postDate": "2017-01-02" }
    { "index": { "_id": 3 }}
    { "articleID" : "JODL-X-1937-#pV7", "userID" : 2, "hidden": false, "postDate": "2017-01-01" }
    { "index": { "_id": 4 }}
    { "articleID" : "QQPX-R-3956-#aD8", "userID" : 2, "hidden": true, "postDate": "2017-01-02" }
    
    
    GET /forum/article/_search
    {
        "query" : {
            "constant_score" : { 
                "filter" : {
                    "term" : { 
                        "articleID" : "XHDK-A-1293-#fJ3"
                    }
                }
            }
        }
    }
    PUT test_index/test_type/1
    {
      "test_field":"test1"
    }
    
    
    GET  test_index/test_type/_search
    
    PUT test_index/test_type/1?version=1
    {
      "test_field":"test3"
    }
    
    GET website/_search
    GET website/_mapping/blogs
    
    
    GET /website/_analyze
    {
      "field": "content",
      "text": "my-dogs" 
    }
    
    GET /_analyze
    {
      "analyzer": "ik_max_word",
      "text": "中华人民共和国"
    }
    
    GET /_analyze
    {
      "analyzer": "standard",
      "text": "中华人民共和国"
    }
    
    GET /_analyze
    {
      "analyzer": "index_ansj",
      "text": "中华人民共和国"
    }
    
    
    
    GET /jd_item/_mapping
    
    GET /jd_item/jd_item/_search
    {
      "query": {
        "match": {
          "title": "飞利浦"
        }
      }
    }
    
    
    
    
    
    
    
    GET /jd_item/jd_item/_search
    {
      "from":0,
      "size":20,
      "query": {
        "bool": {
          "must": [
            {
             "query_string": {
              "default_field": "title",
              "query": "飞利浦"
             }
            },
            {
              "query_string": {
                "default_field": "id",
                "query": "1106502"
              }
            }
          ]
        }
      }
    }
    
    GET /jd_item/jd_item/_search
    {
      "query": {
        "match": {
          "title": "飞利"
        }
      }
    }
    GET /tvs/sales/_search
    {
       "size" : 0,
       "aggs":{
          "price":{
             "histogram":{ 
                "field": "price",
                "interval": 2000
             },
             "aggs":{
                "revenue": {
                   "sum": { 
                     "field" : "price"
                   }
                 }
             }
          }
       }
    }
    
    GET /tvs/sales/_search 
    {
      "size": 0,
      "query": {
        "term": {
          "brand": {
            "value": "长虹"
          }
        }
      },
      "aggs": {
        "recent_150d": {
          "filter": {
            "range": {
              "sold_date": {
                "gte": "now-150d"
              }
            }
          },
          "aggs": {
            "recent_150d_avg_price": {
              "avg": {
                "field": "price"
              }
            }
          }
        },
        "recent_140d": {
          "filter": {
            "range": {
              "sold_date": {
                "gte": "now-140d"
              }
            }
          },
          "aggs": {
            "recent_140d_avg_price": {
              "avg": {
                "field": "price"
              }
            }
          }
        },
        "recent_130d": {
          "filter": {
            "range": {
              "sold_date": {
                "gte": "now-130d"
              }
            }
          },
          "aggs": {
            "recent_130d_avg_price": {
              "avg": {
                "field": "price"
              }
            }
          }
        }
      }
    }
    
    GET /spnews/news/_search
    {
      "query": {
        "multi_match": {
          "query": "足球",
          "fields": [
            "content^1.0",
            "title^1.0"
          ],
          "type": "best_fields",
          "operator": "OR",
          "slop": 0,
          "prefix_length": 0,
          "max_expansions": 50,
          "lenient": false,
          "zero_terms_query": "NONE",
          "boost": 1
        }
      },
      "highlight": {
        "pre_tags": [
          "<font style='color:red'>"
        ],
        "post_tags": [
          "</font>"
        ],
        "fields": {
          "title": {},
          "content": {}
        }
      }
    }
    GET /spnews/news/_search
    {
      "from": 0,
      "size": 28,
      "query": {
        "bool": {
          "must": [
            {
              "bool": {
                "should": [
                  {
                    "match": {
                      "productCommonName": {
                        "query": "感冒药",
                        "type": "boolean",
                        "operator": "AND",
                        "boost": 4
                      }
                    }
                  },
                  {
                    "match": {
                      "productName": {
                        "query": "感冒药",
                        "type": "boolean",
                        "operator": "AND",
                        "boost": 1
                      }
                    }
                  },
                  {
                    "match": {
                      "productChnNo": {
                        "query": "感冒药",
                        "type": "boolean",
                        "operator": "AND",
                        "boost": 1
                      }
                    }
                  },
                  {
                    "match": {
                      "proCatalogName": {
                        "query": "感冒药",
                        "type": "boolean",
                        "operator": "AND",
                        "boost": 4
                      }
                    }
                  },
                  {
                    "match": {
                      "productBrandName": {
                        "query": "感冒药",
                        "type": "boolean",
                        "operator": "AND",
                        "boost": 4
                      }
                    }
                  },
                  {
                    "match": {
                      "productBrandName1": {
                        "query": "感冒药",
                        "type": "boolean",
                        "operator": "AND",
                        "boost": 4
                      }
                    }
                  },
                  {
                    "match": {
                      "productKeyword": {
                        "query": "感冒药",
                        "type": "boolean",
                        "operator": "AND",
                        "boost": 4
                      }
                    }
                  }
                ]
              }
            },
            {
              "bool": {
                "should": [
                  {
                    "range": {
                      "saleScore": {
                        "from": 50,
                        "to": null,
                        "include_lower": false,
                        "include_upper": true,
                        "boost": 200
                      }
                    }
                  },
                  {
                    "range": {
                      "saleScore": {
                        "from": null,
                        "to": 50,
                        "include_lower": true,
                        "include_upper": false,
                        "boost": 1
                      }
                    }
                  }
                ]
              }
            }
          ]
        }
      },
      "post_filter": {
        "bool": {
          "must_not": {
            "term": {
              "ecPrice": -1
            }
          }
        }
      },
      "sort": [
        {
          "stock": {
            "order": "desc"
          }
        },
        {
          "_score": {
            "order": "desc"
          }
        }
      ],
      "highlight": {
        "pre_tags": [
          "<em>"
        ],
        "post_tags": [
          "</em>"
        ],
        "fields": {
          "productName": {
            "fragment_size": 70
          }
        }
      }
    }
    GET /test_index/test_type/_search 
    {
        "query": {
            "match": {
                "search_field": "test"
            }
        },
        "aggs": {
            "group_by_agg_field": {
                "terms": {
                    "field": "agg_field"
                }
            }
        }
    }
    
    
    
    
    
    
    
    
    GET /website/users/_search 
    {
      "query": {
        "term": {
          "name.keyword": {
            "value": "小鱼儿"
          }
        }
      }
    }
    
    
    GET /forum/_mapping/article
    
    {
      "forum": {
        "mappings": {
          "article": {
            "properties": {
              "articleID": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "hidden": {
                "type": "boolean"
              },
              "postDate": {
                "type": "date"
              },
              "userID": {
                "type": "long"
              }
            }
          }
        }
      }
    }
    
    GET /forum/article/_search
    
    
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"tag" : ["java", "hadoop"]} }
    { "update": { "_id": "2"} }
    { "doc" : {"tag" : ["java"]} }
    { "update": { "_id": "3"} }
    { "doc" : {"tag" : ["hadoop"]} }
    { "update": { "_id": "4"} }
    { "doc" : {"tag" : ["java", "elasticsearch"]} }
    
    GET /forum/article/_search
    {
        "query" : {
            "constant_score" : {
                "filter" : {
                    "terms" : { 
                        "tag" : ["java"]
                    }
                }
            }
        }
    }
    
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"tag_cnt" : 2} }
    { "update": { "_id": "2"} }
    { "doc" : {"tag_cnt" : 1} }
    { "update": { "_id": "3"} }
    { "doc" : {"tag_cnt" : 1} }
    { "update": { "_id": "4"} }
    { "doc" : {"tag_cnt" : 2} }
    
    
    
    POST /forum/article/_bulk
    { "index": { "_id": 1 }}
    { "articleID" : "XHDK-A-1293-#fJ3", "userID" : 1, "hidden": false, "postDate": "2017-01-01" }
    { "index": { "_id": 2 }}
    { "articleID" : "KDKE-B-9947-#kL5", "userID" : 1, "hidden": false, "postDate": "2017-01-02" }
    { "index": { "_id": 3 }}
    { "articleID" : "JODL-X-1937-#pV7", "userID" : 2, "hidden": false, "postDate": "2017-01-01" }
    { "index": { "_id": 4 }}
    { "articleID" : "QQPX-R-3956-#aD8", "userID" : 2, "hidden": true, "postDate": "2017-01-02" }
    GET /forum/article/_search
    
    GET /forum/article/_search
    {
      "query": {
        "constant_score": {
          "filter": {
            "bool": {
              "must": [
                {
                  "term": {
                    "tag_cnt": 1
                  }
                },
                {
                  "terms": {
                    "tag": ["java"]
                  }
                }
              ]
            }
          }
        }
      }
    }
    
    GET /forum/article/_search
    {
        "query" : {
            "constant_score" : { 
                "filter" : {
                    "term" : { 
                        "hidden" : false
                    }
                }
            }
        }
    }
    
    GET /forum/article/_search
    {
        "query" : {
            "constant_score" : { 
                "filter" : {
                    "term" : { 
                        "postDate" : "2017-01-01"
                    }
                }
            }
        }
    }
    
    GET /forum/article/_search
    {
        "query" : {
            "constant_score" : { 
                "filter" : {
                    "term" : { 
                        "articleID" : "XHDK-A-1293-#fJ3"
                    }
                }
            }
        }
    }
    
    
    GET /forum/article/_search
    {
        "query" : {
            "constant_score" : { 
                "filter" : {
                    "term" : { 
                        "articleID.keyword" : "XHDK-A-1293-#fJ3"
                    }
                }
            }
        }
    }
    POST /forum/article/_bulk
    { "index": { "_id": 1 }}
    { "articleID" : "XHDK-A-1293-#fJ3", "userID" : 1, "hidden": false, "postDate": "2017-01-01" }
    { "index": { "_id": 2 }}
    { "articleID" : "KDKE-B-9947-#kL5", "userID" : 1, "hidden": false, "postDate": "2017-01-02" }
    { "index": { "_id": 3 }}
    { "articleID" : "JODL-X-1937-#pV7", "userID" : 2, "hidden": false, "postDate": "2017-01-01" }
    { "index": { "_id": 4 }}
    { "articleID" : "QQPX-R-3956-#aD8", "userID" : 2, "hidden": true, "postDate": "2017-01-02" }
    GET /forum/article/_search
    {
        "query" : {
            "constant_score" : { 
                "filter" : {
                    "term" : { 
                        "articleID" : "XHDK-A-1293-#fJ3"
                    }
                }
            }
        }
    }
    
    GET /forum/article/_search
    {
        "query": {
            "dis_max": {
                "queries": [
                    { "match": { "title": "java beginner" }},
                    { "match": { "content":  "java beginner" }}
                ]
            }
        }
    }
    GET /forum/article/_search
    {
        "query": {
            "dis_max": {
                "queries": [
                    { "match": { "title": "java beginner" }},
                    { "match": { "content":  "java beginner" }}
                ],
                "tie_breaker": 0.3
            }
        }
    }
    GET /my_index/my_type/_search 
    {
      "query": {
        "match_phrase_prefix": {
          "title": "hello d"
        }
      }
    }
    
    GET /my_index/my_type/_search 
    {
      "query": {
        "fuzzy": {
          "text": {
            "value": "surprize",
            "fuzziness": 2
          }
        }
      }
    }
    
    
    GET /forum/article/_search
    {
      "query": {
        "multi_match": {
          "query":       "Peter Smith",
          "type":        "most_fields",
          "fields":      [ "author_first_name", "author_last_name" ]
        }
      }
    }
    
    
    
    GET /forum/article/_search 
    {
      "query": {
        "bool": {
          "should": [
            {
              "match": {
                "content": "java"
              }
            },
            {
              "match": {
                "content": "spark"
              }
            },
            {
              "bool": {
                "should": [
                  {
                    "match": {
                      "content": "solution"
                    }
                  },
                  {
                    "match": {
                      "content": "beginner"
                    }
                  }
                ]
              }
            }
          ]
        }
      }
    }
    GET /forum/article/_search 
    {
      "query": {
        "bool": {
          "must": [
            {
              "match": {
                "content": "java"
              }
            }
          ],
          "must_not": [
            {
              "match": {
                "content": "spark"
              }
            }
          ]
        }
      }
    }
    
    
    GET /forum/article/_search 
    {
      "query": {
        "boosting": {
          "positive": {
            "match": {
              "content": "java"
            }
          },
          "negative": {
            "match": {
              "content": "spark"
            }
          },
          "negative_boost": 0.2
        }
      }
    }
    
    GET /forum/article/_search 
    {
      "query": {
        "bool": {
          "should": [
            {
              "constant_score": {
                "query": {
                  "match": {
                    "title": "java"
                  }
                }
              }
            },
            {
              "constant_score": {
                "query": {
                  "match": {
                    "title": "spark"
                  }
                }
              }
            }
          ]
        }
      }
    }
    {
      "took": 2,
      "timed_out": false,
      "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
      },
      "hits": {
        "total": 3,
        "max_score": 0.6931472,
        "hits": [
          {
            "_index": "forum",
            "_type": "article",
            "_id": "2",
            "_score": 0.6931472,
            "_source": {
              "articleID": "KDKE-B-9947-#kL5",
              "userID": 1,
              "hidden": false,
              "postDate": "2017-01-02",
              "tag": [
                "java"
              ],
              "tag_cnt": 1,
              "view_cnt": 50,
              "title": "this is java blog",
              "content": "i think java is the best programming language",
              "sub_title": "learned a lot of course",
              "author_first_name": "Smith",
              "author_last_name": "Williams"
            }
          },
          {
            "_index": "forum",
            "_type": "article",
            "_id": "1",
            "_score": 0.5753642,
            "_source": {
              "articleID": "XHDK-A-1293-#fJ3",
              "userID": 1,
              "hidden": false,
              "postDate": "2017-01-01",
              "tag": [
                "java",
                "hadoop"
              ],
              "tag_cnt": 2,
              "view_cnt": 30,
              "title": "this is java and elasticsearch blog",
              "content": "i like to write best elasticsearch article",
              "sub_title": "learning more courses",
              "author_first_name": "Peter",
              "author_last_name": "Smith"
            }
          },
          {
            "_index": "forum",
            "_type": "article",
            "_id": "5",
            "_score": 0.51623213,
            "_source": {
              "articleID": "DHJK-B-1395-#Ky5",
              "userID": 3,
              "hidden": false,
              "postDate": "2017-03-01",
              "tag": [
                "elasticsearch"
              ],
              "tag_cnt": 1,
              "view_cnt": 10,
              "title": "this is spark blog",
              "content": "spark is best big data solution based on scala ,an programming language similar to java",
              "sub_title": "haha, hello world",
              "author_first_name": "Tonny",
              "author_last_name": "Peter Smith"
            }
          }
        ]
      }
    }
    
    PUT /tvs
    {
        "mappings": {
            "sales": {
                "properties": {
                    "price": {
                        "type": "long"
                    },
                    "color": {
                        "type": "keyword"
                    },
                    "brand": {
                        "type": "keyword"
                    },
                    "sold_date": {
                        "type": "date"
                    }
                }
            }
        }
    }
    
    POST /tvs/sales/_bulk
    { "index": {}}
    { "price" : 1000, "color" : "红色", "brand" : "长虹", "sold_date" : "2016-10-28" }
    { "index": {}}
    { "price" : 2000, "color" : "红色", "brand" : "长虹", "sold_date" : "2016-11-05" }
    { "index": {}}
    { "price" : 3000, "color" : "绿色", "brand" : "小米", "sold_date" : "2016-05-18" }
    { "index": {}}
    { "price" : 1500, "color" : "蓝色", "brand" : "TCL", "sold_date" : "2016-07-02" }
    { "index": {}}
    { "price" : 1200, "color" : "绿色", "brand" : "TCL", "sold_date" : "2016-08-19" }
    { "index": {}}
    { "price" : 2000, "color" : "红色", "brand" : "长虹", "sold_date" : "2016-11-05" }
    { "index": {}}
    { "price" : 8000, "color" : "红色", "brand" : "三星", "sold_date" : "2017-01-01" }
    { "index": {}}
    { "price" : 2500, "color" : "蓝色", "brand" : "小米", "sold_date" : "2017-02-12" }
    
    
    GET /tvs/sales/_search
    {
        "size" : 0,
        "aggs" : { 
            "popular_colors" : { 
                "terms" : { 
                  "field" : "color"
                }
            }
        }
    }
    
    GET /tvs/sales/_search 
    {
      "size": 0,
      "query": {
        "constant_score": {
          "filter": {
            "range": {
              "price": {
                "gte": 1200
              }
            }
          }
        }
      },
      "aggs": {
        "avg_price": {
          "avg": {
            "field": "price"
          }
        }
      }
    }
    GET /tvs/sales/_search
    {
      "size" : 0,
      "aggs" : {
          "months" : {
            "date_histogram": {
              "field": "sold_date",
              "interval": "month"
            },
            "aggs": {
              "distinct_colors" : {
                  "cardinality" : {
                    "field" : "brand"
                  }
              }
            }
          }
      }
    }
    
    PUT /blog_website
    {
      "mappings": {
        "blogs": {
          "properties": {
            "title": {
              "type": "text",
              "analyzer": "ik_max_word"
            },
            "content": {
              "type": "text",
              "analyzer": "ik_max_word"
            }
          }
        }
      }
    }
    
    PUT /blog_website/blogs/1
    {
      "title": "我的第一篇博客",
      "content": "大家好,这是我写的第一篇博客,特别喜欢这个博客网站!!!"
    }
    
    
    GET /blog_website/blogs/_search 
    {
      "query": {
        "match": {
          "title": "博客"
        }
      },
      "highlight": {
        "fields": {
          "title": {}
        }
      }
    }
    
    
    
    GET /blog_website/blogs/_search 
    {
      "query": {
        "bool": {
          "should": [
            {
              "match": {
                "title": "博客"
              }
            },
            {
              "match": {
                "content": "博客"
              }
            }
          ]
        }
      },
      "highlight": {
        "fields": {
          "title": {},
          "content": {}
        }
      }
    }
    
    
    PUT /news_website
    {
      "mappings": {
        "news" : {
          "properties" : {
            "title" : {
              "type": "text",
              "analyzer": "ik_max_word",
              "fields": {
                "suggest" : {
                  "type" : "completion",
                  "analyzer": "ik_max_word"
                }
              }
            },
            "content": {
              "type": "text",
              "analyzer": "ik_max_word"
            }
          }
        }
      }
    }
    
    PUT /news_website_pinyin
    {
      "mappings": {
        "news_pinyin" : {
          "properties" : {
            "title" : {
              "type": "text",
              "analyzer": "pinyin_analyzer",
              "fields": {
                "suggest" : {
                  "type" : "completion",
                  "analyzer": "pinyin_analyzer"
                }
              }
            },
            "content": {
              "type": "text",
              "analyzer": "pinyin_analyzer"
            }
          }
        }
      }
    }
    
    
    
    PUT /medcl1/
    {
        "index" : {
            "analysis" : {
                "analyzer" : {
                    "ngram_pinyin_analyzer" : {
                        "tokenizer" : "keyword",
                        "filter" : ["full_pinyin_with_space","word_delimiter","shingle","remove_whitespace"]
                    }, "my_pinyin_analyzer" : {
                        "tokenizer" : "keyword",
                        "filter" : ["full_pinyin_no_space"]
                    }
                },
                "filter" :{
                    "full_pinyin_no_space" : {
                        "type" : "pinyin",
                        "first_letter" : "none",
                        "padding_char" : ""
                },"full_pinyin_with_space" : {
                        "type" : "pinyin",
                        "first_letter" : "none",
                        "padding_char" : " "
                },
                 "my_edge_ngram_tokenizer" : {
                            "type" : "edgeNGram",
                            "min_gram" : "2",
                            "max_gram" : "5",
                            "token_chars": [ "letter", "digit" ]
                        },
                        "remove_whitespace": {
                        "type":       "pattern_replace",
                        "pattern": "\s+",
                        "replacement":""
                    }
            }
            }
        }
    }
    
    POST medcl1/type/_mapping
    {
      "properties": {
        "name1":{
          "type": "multi_field",
          "fields": {
            "pinyin":{
              "type": "string", 
              "analyzer": "ngram_pinyin_analyzer"
            }, "full_pinyin":{
              "type": "string", 
              "analyzer": "my_pinyin_analyzer"
            },
            "first_letter":{
              "type": "string", 
              "analyzer": "pinyin_first_letter"
            },
            "name1":{
              "type": "string", 
              "analyzer": "ik_max_word"
            }
          }
        }
      }
    }
    
    
    GET medcl1/_mapping
    
    
    POST medcl1/type3/
    {
      "name1":"刘德华"
    }
    POST medcl1/type3/
    {
      "name1":"刘斌"
    }
    POST medcl1/type3/
    {
      "name1":"张三"
    }
    POST medcl1/type3/
    {
      "name1":"李四"
    }
    POST medcl1/type3/
    {
      "name1":"刘德志"
    }
    
    POST medcl1/_search?size=50
    {
      "query": {
        "query_string": {
          "fields": ["name1","name1.full_pinyin","name1.pinyin","name1.first_letter"],
          "query": "刘德华",
          "default_operator": "AND"
        }
      }
    }
    
    PUT /search_text
    {
      "settings": {
        "refresh_interval": "5s",
        "number_of_shards": 1,
        "number_of_replicas": 1,
        "analysis": {
          "filter": {
            "edge_ngram_filter": {
              "type": "edge_ngram",
              "min_gram": 1,
              "max_gram": 50
            },
            "pinyin_full_filter": {
              "type": "pinyin",
              "keep_first_letter": false,
              "keep_separate_first_letter": false,
              "keep_full_pinyin": true,
              "keep_original": false,
              "limit_first_letter_length": 50,
              "lowercase": true
            },
            "pinyin_simple_filter": {
              "type": "pinyin",
              "keep_first_letter": true,
              "keep_separate_first_letter": false,
              "keep_full_pinyin": false,
              "keep_original": false,
              "limit_first_letter_length": 50,
              "lowercase": true
            }
          },
          "analyzer": {
            "pinyiSimpleIndexAnalyzer": {
              "type": "custom",
              "tokenizer": "keyword",
              "filter": [
                "pinyin_simple_filter",
                "edge_ngram_filter",
                "lowercase"
              ]
            },
            "pinyiFullIndexAnalyzer": {
              "type": "custom",
              "tokenizer": "keyword",
              "filter": [
                "pinyin_full_filter",
                "lowercase"
              ]
            }
          }
        }
      }
    }
    
    
    PUT /search_text/_mapping/list
    {
      "properties": {
        "name": {
          "type": "keyword",
          "fields": {
            "fpy": {
              "type": "text",
              "index": true,
              "analyzer": "pinyiFullIndexAnalyzer"
            },
            "spy": {
              "type": "text",
              "index": true,
              "analyzer": "pinyiSimpleIndexAnalyzer"
            }
          }
        }
      }
    }
    
     
    PUT /search_text/list/4
    {
      "name":"刘德华"
    }
    
    
    
    
    PUT /search_text/list/2
    {
      "name":"天命"
    }
    PUT /search_text/list/3
    {
      "name":"你好明天"
    }
    POST /search_text/list/_search
    {
      "query":{
          "match":{
              "name.fpy":{
                  "query":"liudehua",
                  "operator": "and"
              }
          }
      }
    }
    
    GET  /news_website/news/_mapping
    
    PUT /news_website/news/1
    {
      "title": "大话西游电影dhxy",
      "content": "大话西游的电影时隔20年即将在2017年4月重映"
    }
    PUT /news_website/news/2
    {
      "title": "大话西游小说dhxy",
      "content": "某知名网络小说作家已经完成了大话西游同名小说的出版"
    }
    PUT /news_website/news/3
    {
      "title": "大话西游手游dhxy",
      "content": "网易游戏近日出品了大话西游经典IP的手游,正在火爆内测中"
    }
    
    GET /news_website/news/_search
    {
      "suggest": {
        "my-suggest" : {
          "prefix" : "dhxy",
          "completion" : {
            "field" : "title.suggest"
          }
        }
      }
    }
    GET /news_website/news/_search 
    {
      "query": {
        "match": {
          "content": "大话西游电影"
        }
      }
    }
    
    
    PUT /my_index
    {
      "mappings": {
        "my_type": {
          "properties": {
            "text": {
                "type": "text",
                "term_vector": "with_positions_offsets_payloads",
                "store" : true,
                "analyzer" : "fulltext_analyzer"
             },
             "fullname": {
                "type": "text",
                "analyzer" : "fulltext_analyzer"
            }
          }
        }
      },
      "settings" : {
        "index" : {
          "number_of_shards" : 1,
          "number_of_replicas" : 0
        },
        "analysis": {
          "analyzer": {
            "fulltext_analyzer": {
              "type": "custom",
              "tokenizer": "whitespace",
              "filter": [
                "lowercase",
                "type_as_payload"
              ]
            }
          }
        }
      }
    }
    
    
    PUT /my_index/my_type/1
    {
      "fullname" : "Leo Li",
      "text" : "hello test test test "
    }
    
    PUT /my_index/my_type/2
    {
      "fullname" : "Leo Li",
      "text" : "other hello test ..."
    }
    
    GET /my_index/my_type/1/_termvectors
    {
      "fields" : ["text"],
      "offsets" : true,
      "payloads" : true,
      "positions" : true,
      "term_statistics" : true,
      "field_statistics" : true
    }
    
    {
      "_index": "my_index",
      "_type": "my_type",
      "_id": "1",
      "_version": 1,
      "found": true,
      "took": 10,
      "term_vectors": {
        "text": {
          "field_statistics": {
            "sum_doc_freq": 6,
            "doc_count": 2,
            "sum_ttf": 8
          },
          "terms": {
            "hello": {
              "doc_freq": 2,
              "ttf": 2,
              "term_freq": 1,
              "tokens": [
                {
                  "position": 0,
                  "start_offset": 0,
                  "end_offset": 5,
                  "payload": "d29yZA=="
                }
              ]
            },
            "test": {
              "doc_freq": 2,
              "ttf": 4,
              "term_freq": 3,
              "tokens": [
                {
                  "position": 1,
                  "start_offset": 6,
                  "end_offset": 10,
                  "payload": "d29yZA=="
                },
                {
                  "position": 2,
                  "start_offset": 11,
                  "end_offset": 15,
                  "payload": "d29yZA=="
                },
                {
                  "position": 3,
                  "start_offset": 16,
                  "end_offset": 20,
                  "payload": "d29yZA=="
                }
              ]
            }
          }
        }
      }
    }
    GET /my_index/my_type/1/_termvectors
    {
      "fields" : ["fullname"],
      "offsets" : true,
      "positions" : true,
      "term_statistics" : true,
      "field_statistics" : true
    }GET /my_index/my_type/_termvectors
    {
      "doc" : {
        "fullname" : "Leo Li",
        "text" : "hello test test test"
      },
      "fields" : ["text"],
      "offsets" : true,
      "payloads" : true,
      "positions" : true,
      "term_statistics" : true,
      "field_statistics" : true
    }
    GET /company/rd_center/_search 
    {
      "size": 0,
      "aggs": {
        "group_by_country": {
          "terms": {
            "field": "country.keyword"
          },
          "aggs": {
            "group_by_child_employee": {
              "children": {
                "type": "employee"
              },
              "aggs": {
                "group_by_hobby": {
                  "terms": {
                    "field": "hobby.keyword"
                  }
                }
              }
            }
          }
        }
      }
    }
    
    
    
    
    GET /movies/_search
    {
      "from": 0, 
      "size": 10000, 
      "query": {
        "match_all": {}
      }
    }
    
    GET /forum/_search
    
    GET /forum/_mapping/article
    
    
    GET /forum/_search
    {
      "query": {
        "constant_score": {
          "filter": {
            "term": {
              "userID": "1"
            }
          }
        }
      }
    }
    
    
    GET /forum/_search
    {
      "query": {
        "bool": {
          "must_not": [
            {
              "term": {
                "postDate": {
                  "value": "2017-01-02"
                }
              }
            }
          ],
          "should": [
            {
              "term": {
                "postDate": "2017-01-01"
              }
            },
            {
              "term": {
                "articleID": "XHDK-A-1293-#fJ3"
              }
            }
          ]
        }
      }
    }
    
     GET /forum/_search
    {
      "query": {
        "bool": {
          "should": [
            {
              "term": {
                "postDate":"2017-01-01"
                
              }
            },{
              "term": {
                "articleID":"XHDK-A-1293-#fJ3"
              }
            }
          ]
        }
      }
    }
     GET /forum/_search
    {
      "query": {
        "bool": {
          "should": [
            {
              "term": {
                 "postDate":"2017-01-01"
              }
            },{
              "term": {
                "articleID":"XHDK-A-1293-#fJ3"
              }
            }
          ],
          "must_not": [
            {
              "term": {
                "postDate":"2017-01-02"
              }
            }
          ]
        }
      }
    }
    GET /forum/_search
    {
      "query": {
        "constant_score": {
          "filter": {
            "bool": {
              "should": [
                {
                  "term": {
                "articleID": "XHDK-A-1293-#fJ3"
                  }
                }
              ],
              "bool": {
                "must": [
                  {
                    "term": {
                    "articleID": "JODL-X-1937-#pV7"
                    }
                  }
                ]
              }
            }
          }
        }
      }
    }
    
    GET /forum/article/_search
    {
      "query": {
        "constant_score": {
          "filter": {
            "bool": {
              "should": [
                {
                  "term": {
                    "articleID": "XHDK-A-1293-#fJ3"
                  }
                },
                {
                  "bool": {
                    "must": [
                      {
                        "term": {
                          "articleID": "JODL-X-1937-#pV7"
                        }
                      },
                      {
                        "term": {
                          "postDate": "2017-01-01"
                        }
                      }
                    ]
                  }
                }
              ]
            }
          }
        }
      }
    }
    
    #搜索帖子ID为XHDK-A-1293-#fJ3,或者是帖子ID为JODL-X-1937-#pV7而且发帖日期为2017-01-01的帖子
    
    
    GET /forum/article/_search
    {
      "query": {
        "constant_score": {
          "filter": {
            "bool": {
              "should": [
                {
                  "term": {
                    "articleID": "XHDK-A-1293-#fJ3"
                  }
                },
                {
                  "bool": {
                    "must": [
                      {
                        "term": {
                          "postDate": "2017-01-01"
                        }
                      },
                      {
                        "term":{
                          "articleID": "JODL-X-1937-#pV7"
                        }
                      }
                    ]
                  }
                }
              ]
            }
          }
        }
      }
    }
    GET /forum/article/_search
    {
      "query": {
        "bool": {
          "must": [
           {
              "term": {
                 "postDate": "2017-01-01"
              }
            }
          ],
          "should": [
            {
              "term": {
                 "articleID": "XHDK-A-1293-#fJ3"
              }
            }, {
              "term": {"articleID": "JODL-X-1937-#pV7"
              }
            }
          ]
        }
      }
    }
    GET /forum/article/_search 
    {
      "query": {
        "constant_score": {
          "filter": {
            "terms": {
              "articleID": [
                "KDKE-B-9947-#kL5",
                "QQPX-R-3956-#aD8"
              ]
            }
          }
        }
      }
    }
    
    GET /forum/article/_search 
    {
      "query": {
        "constant_score": {
          "filter": {
            "terms": {
              "articleID": [
               "KDKE-B-9947-#kL5",
                "QQPX-R-3956-#aD8"
              ]
            }
          }
        }
      }
    }
    GET /forum/article/_search
    {
      "query": {
        "constant_score": {
          "filter": {
            "terms": {
              "tag" : ["java"]
            }
          }
        }
      }
    }
    
    
    
    
    
    
    
    GET /forum/article/_search
    {
      "query": {
        "constant_score": {
          "filter": {
            "bool": {
              "must": [
                {
                  "term": {
                    "tag_cnt": 1
                  }
                },
                {
                  "terms": {
                    "tag": ["java"]
                  }
                }
              ]
            }
          }
        }
      }
    }
    
    
    GET /forum/article/_search
    {
      "query": {
        "constant_score": {
         "filter": {
           "bool": {
             "must":[
               {
                 "term":{
                    "tag_cnt": 1
                 }
               },{
                 "terms":{
                      "tag": ["java"]
                 }
               }
               ]
           }
         }
        }
      }
    }
    
    GET /forum/article/_search
    {
      "query": {
        "constant_score": {
          "filter": {
            "range": {
              "view_cnt": {
                "gte": 30,
                "lte": 60
              }
            }
          }
          
        }
      }
    }
    #最近一个月的帖子 
    GET /forum/article/_search 
    {
      "query": {
        "constant_score": {
          "filter": {
            "range": {
              "postDate": {
              "gt": "2017-03-10||-30d"
              }
            }
          }
        }
      }
    }
    
    GET /forum/article/_search 
    {
      "query": {
        "constant_score": {
          "filter": {
            "range": {
              "postDate": {
                "gte": "now-30d"
              }
            }
          }
        }
      }
    }
    GET /forum/article/_mapping
    GET /forum/article/_search
    {
      "query": {
        "match": {
          "title": "java elasticsearch"
        }
      }
    }
    
    
    
    GET /forum/article/_search
    {
      "query": {
        "match": {
          "title": {
            "query": "java elasticsearch",
            "operator": "and"
          }
        }
      }
    }
    GET /forum/article/_search
    {
      "query": {
        "match": {
          "title":{
            "query": "java elasticsearch spark hadoop",
            "minimum_should_match": "75%"
          }
        }
      }
    }
    GET /forum/article/_search
    {
      "query": {
      "bool": {
        "must": [
          {
            "match": {
              "title": "java" 
            }
          }
        ],"must_not": [
          {
            "match": {
             "title": "spark"  
            }
          }
        ],
        "should": [
          {
            "match": {
              "title": "hadoop"
            }
          },{
            "match": {
              "title": "elasticsearch"
            }
          }
        ]
      }
      }
    }
    GET /forum/article/_search
    {
      "query": {
        "bool": {
          "must": {
            "match": {
              "title": "java"
            }
          },
          "must_not": {
            "match": {
              "title": "spark"
            }
          },
          "should": [
            {
              "match": {
                "title": "hadoop"
              }
            },
            {
              "match": {
                "title": "elasticsearch"
              }
            }
          ]
        }
      }
    }
    GET /forum/article/_search
    {
      "query": {
        "bool": {
          "should": [
            {
              "match": {
               "title": "java"
              }
            },
            {
              "match": {
                "title": "elasticsearch"  
              }
            },
            {
              "match": {
                "title": "spark"  
              }
            },
            {
              "match": {
                "title": "hadoop"  
              }
            }
            
          ],
          "minimum_should_match": 3
        }
      }
    }
    
    GET /forum/article/_search
    {
      "query": {
        "match": {
          "title": {
           "query": "",
           "operator": "and"
          }
        }
      }
    }
    
    
    
    GET /forum/article/_search 
    {
      "query": {
        "bool": {
          "must": [
            {
              "match": {
                "title": "blog"
              }
            }
          ],
          "should": [
            {
              "match": {
                "title": {
                  "query": "java"
                }
              }
            },
            {
              "match": {
                "title": {
                  "query": "hadoop"
                }
              }
            },
            {
              "match": {
                "title": {
                  "query": "elasticsearch"
                }
              }
            },
            {
              "match": {
                "title": {
                  "query": "spark",
                  "boost": 5
                }
              }
            }
          ]
        }
      }
    }
    
    
    
    
    
    
    GET /forum/article/_search 
    {
      "query": {
        "bool": {
          "must": [
            {
              "match": {
                "title": "blog"
              }
            }
          ],
          "should": [
            {
              "match": {
                "title": {
                  "query": "java"
                }
              }
            },
            {
              "match": {
                "title": {
                  "query": "hadoop"
                }
              }
            },
            {
              "match": {
                "title": {
                  "query": "elasticsearch"
                }
              }
            },
            {
              "match": {
                "title": {
                  "query": "spark",
                  "boost": 5
                }
              }
            }
          ]
        }
      }
    }
    
    GET /forum/article/_search
    {
        "query": {
            "bool": {
                "should": [
                    { "match": { "title": "java solution" }},
                    { "match": { "content":  "java solution" }}
                ]
            }
        }
    }
    
    GET /forum/article/_search
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"content" : "i like to write best elasticsearch article"} }
    { "update": { "_id": "2"} }
    { "doc" : {"content" : "i think java is the best programming language"} }
    { "update": { "_id": "3"} }
    { "doc" : {"content" : "i am only an elasticsearch beginner"} }
    { "update": { "_id": "4"} }
    { "doc" : {"content" : "elasticsearch and hadoop are all very good solution, i am a beginner"} }
    { "update": { "_id": "5"} }
    { "doc" : {"content" : "spark is best big data solution based on scala ,an programming language similar to java"} }
    GET /forum/article/_search
    {
      "query":{
        "bool": {
          "should": [
            {
              "match": {
               "content":  "java solution"
              }
            },{
              "match": {
               "title": "java solution"
              }
            }
          ]
        }
      }
    }
    GET /forum/article/_search
    
    GET /forum/article/_search
    {
      "query": {
        "bool": {
          "should": [
            {
              "match": {
                "content":  "java solution"
              }
            },
            {
              "match": {
              "title": "java solution"
              }
            }
          ]
        }
      }
    }
    
    GET /forum/article/_search
    {
      "query": {
        "dis_max": {
          "queries": [
            {
              "match": {
               "title": "java solution"
              }
            },{
              "match": {
               "content":  "java solution"
              }
            }
            ]
        }
      }
    }
    
    GET /forum/article/_search
    {
        "query": {
            "dis_max": {
                "queries": [
                    { "match": { "title": "java beginner" }},
                    { "match": { "content":  "java beginner" }}
                ],
                "tie_breaker": 0.3
                
            }
        }
    }
    
    GET /forum/article/_search
    {
      "query": {
        "multi_match": {
          "query": "java solution",
          "fields": [ "title^2", "content" ],
                  "tie_breaker":          0.3,
            "minimum_should_match": "50%" 
    
        }
      }
    }
    
    GET /forum/article/_search
    {
      "query": {
        "match": {
          "sub_title": "learning courses"
        }
      }
    }
    
    GET /forum/article/_search
    {
      "query": {
        "match": {
          "sub_title": "Tlearning courses"
        }
      }
    }
    GET /forum/article/_mapping
    
    
    POST /forum/_mapping/article
    {
      "properties": {
          "sub_title": { 
              "type":     "string",
              "analyzer": "english",
              "fields": {
                  "std":   { 
                      "type":     "string",
                      "analyzer": "standard"
                  }
              }
          }
      }
    }
    
    
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"sub_title" : "learning more courses"} }
    { "update": { "_id": "2"} }
    { "doc" : {"sub_title" : "learned a lot of course"} }
    { "update": { "_id": "3"} }
    { "doc" : {"sub_title" : "we have a lot of fun"} }
    { "update": { "_id": "4"} }
    { "doc" : {"sub_title" : "both of them are good"} }
    { "update": { "_id": "5"} }
    { "doc" : {"sub_title" : "haha, hello world"} }
    
    GET /forum/article/_search
    
    GET /forum/article/_search
    {
      "query": {
        "match": {
          "sub_title": "learning courses"
        }
      }
    }
    
    POST /forum/_mapping/article
    {
      "properties": {
          "sub_title": { 
              "type":     "string",
              "analyzer": "english",
              "fields": {
                  "std":   { 
                      "type":     "string",
                      "analyzer": "standard"
                  }
              }
          }
      }
    }
    post /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"sub_title" : "learning more courses"} }
    { "update": { "_id": "2"} }
    { "doc" : {"sub_title" : "learned a lot of course"} }
    { "update": { "_id": "3"} }
    { "doc" : {"sub_title" : "we have a lot of fun"} }
    { "update": { "_id": "4"} }
    { "doc" : {"sub_title" : "both of them are good"} }
    { "update": { "_id": "5"} }
    { "doc" : {"sub_title" : "haha, hello world"} }
    
    
    GET /forum/article/_search
    {
      "query": {
        "match": {
          "sub_title": "learning courses"
        }
      }
    }
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"title" : "this is java and elasticsearch blog"} }
    { "update": { "_id": "2"} }
    { "doc" : {"title" : "this is java blog"} }
    { "update": { "_id": "3"} }
    { "doc" : {"title" : "this is elasticsearch blog"} }
    { "update": { "_id": "4"} }
    { "doc" : {"title" : "this is java, elasticsearch, hadoop blog"} }
    { "update": { "_id": "5"} }
    { "doc" : {"title" : "this is spark blog"} }
    
    
    get /forum/article/_search
    
    
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"title" : "this is java and elasticsearch blog"} }
    { "update": { "_id": "2"} }
    { "doc" : {"title" : "this is java blog"} }
    { "update": { "_id": "3"} }
    { "doc" : {"title" : "this is elasticsearch blog"} }
    { "update": { "_id": "4"} }
    { "doc" : {"title" : "this is java, elasticsearch, hadoop blog"} }
    { "update": { "_id": "5"} }
    { "doc" : {"title" : "this is spark blog"} }
    
    
    
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"tag" : ["java", "hadoop"]} }
    { "update": { "_id": "2"} }
    { "doc" : {"tag" : ["java"]} }
    { "update": { "_id": "3"} }
    { "doc" : {"tag" : ["hadoop"]} }
    { "update": { "_id": "4"} }
    { "doc" : {"tag" : ["java", "elasticsearch"]} }
    
    
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"title" : "this is java and elasticsearch blog"} }
    { "update": { "_id": "2"} }
    { "doc" : {"title" : "this is java blog"} }
    { "update": { "_id": "3"} }
    { "doc" : {"title" : "this is elasticsearch blog"} }
    { "update": { "_id": "4"} }
    { "doc" : {"title" : "this is java, elasticsearch, hadoop blog"} }
    { "update": { "_id": "5"} }
    { "doc" : {"title" : "this is spark blog"} }
    
    
    POST /forum/_mapping/article
    {
      "properties": {
          "sub_title": { 
              "type":     "string",
              "analyzer": "english",
              "fields": {
                  "std":   { 
                      "type":     "string",
                      "analyzer": "standard"
                  }
              }
          }
      }
    }
    
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"sub_title" : "learning more courses"} }
    { "update": { "_id": "2"} }
    { "doc" : {"sub_title" : "learned a lot of course"} }
    { "update": { "_id": "3"} }
    { "doc" : {"sub_title" : "we have a lot of fun"} }
    { "update": { "_id": "4"} }
    { "doc" : {"sub_title" : "both of them are good"} }
    { "update": { "_id": "5"} }
    { "doc" : {"sub_title" : "haha, hello world"} }
    
    
    
    GET /forum/article/_search
    {
      "query": {
        "match": {
          "sub_title": "learning courses"
        }
      }
    }
    GET /forum/article/_search
    {
       "query": {
            "match": {
                "sub_title": "learning courses"
            }
        }
    }
    
    
    GET /forum/article/_search
    {
       "query": {
            "multi_match": {
                "query":  "learning courses",
                "type":   "most_fields", 
                "fields": [ "sub_title", "sub_title.std" ]
            }
        }
    }
    
    
    
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"author_first_name" : "Peter", "author_last_name" : "Smith"} }
    { "update": { "_id": "2"} }
    { "doc" : {"author_first_name" : "Smith", "author_last_name" : "Williams"} }
    { "update": { "_id": "3"} }
    { "doc" : {"author_first_name" : "Jack", "author_last_name" : "Ma"} }
    { "update": { "_id": "4"} }
    { "doc" : {"author_first_name" : "Robbin", "author_last_name" : "Li"} }
    { "update": { "_id": "5"} }
    { "doc" : {"author_first_name" : "Tonny", "author_last_name" : "Peter Smith"} }
    
    
    GET /forum/article/_search
    {
      "query": {
        "multi_match": {
          "query": "Peter Smith",
          "type": "most_fields", 
          "fields": ["author_first_name","author_last_name"]
        }
      }
    }
    
    PUT /forum/_mapping/article
    {
      "properties": {
          "new_author_first_name": {
              "type":     "string",
              "copy_to":  "new_author_full_name" 
          },
          "new_author_last_name": {
              "type":     "string",
              "copy_to":  "new_author_full_name" 
          },
          "new_author_full_name": {
              "type":     "string"
          }
      }
    }
    
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"new_author_first_name" : "Peter", "new_author_last_name" : "Smith"} }    
    { "update": { "_id": "2"} }    
    { "doc" : {"new_author_first_name" : "Smith", "new_author_last_name" : "Williams"} }    
    { "update": { "_id": "3"} }
    { "doc" : {"new_author_first_name" : "Jack", "new_author_last_name" : "Ma"} }        
    { "update": { "_id": "4"} }
    { "doc" : {"new_author_first_name" : "Robbin", "new_author_last_name" : "Li"} }        
    { "update": { "_id": "5"} }
    { "doc" : {"new_author_first_name" : "Tonny", "new_author_last_name" : "Peter Smith"} }    
    
    
    GET /forum/article/_search
    {
      "query": {
        "match": {
          "new_author_full_name":       "Peter Smith"
        }
      }
    }
    GET /forum/article/_search
    {
      "from": 0,
      "size": 20, 
      "query": {
        "match": {
          "content": "java "
        }
      }
    }
    GET /forum/article/_search
    {
      "query": {
        "match_phrase": {
          "content": "java  spark"
        }
      }
    }
    
    POST /forum/article/3/_update
    {
      "doc": {
        "content": "spark is best big data solution based on scala ,an programming language similar to java spark"
      }
    }
    
    GET /_analyze
    {
      "text": "hello world, java spark",
      "analyzer": "standard"
    }
    
    GET /forum/article/_search
    {
        "query": {
            "match_phrase": {
                "content": "java spark"
            }
        }
    }
    
    GET /forum/article/_search
    {
      "query": {
        "match_all": {}
      }
    }
    
    GET /forum/article/_search
    {
      "query": {
        "match_phrase": {
          "content": {
            "query": "java best",
            "slop": 10
          }
        }
      }
    }
    GET /forum/article/_search
    {
      "query": {
        "bool": {
          "must": [
            {
              "match": {
                "content": "java spark"
              }
            }
          ],
          "should": [
            {
              "match_phrase": {
                "content":{
                  "query": "java spark",
                  "slop":50
                }
              }
            }
          ]
        }
      }
    }
    GET /forum/article/_search 
    {
      "query": {
        "match": {
          "content": "java spark"
        }
      },
      "rescore": {
        "window_size": 50,
        "query": {
          "rescore_query": {
            "match_phrase": {
              "content": {
                "query": "java spark",
                "slop": 50
              }
            }
          }
        }
      }
    }
    
    
    GET /forum/article/_search
    {
      "query": {
        "bool": {
          "should": [
            {
              "match": {
                "title": {
                  "query": "java spark",
                  "boost":2
                }
              }
            },
            {
              "match":{
                
                  "content": "java spark"
                
              }
            }
          ]
        }
      }
    }
    
    
    GET /forum/article/_search
    {
      "query": {
        "bool": {
          "should": [
            {
              "match": {
                "title": {
                  "query": "java spark",
                  "boost": 2
                }
              }
            },
            {
              "match": {
                "content": "java spark"
              }
            }
          ]
        }
      }
    }
    
    
    
    
    
    
    
    
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"content" : "i like to write best elasticsearch article"} }
    { "update": { "_id": "2"} }
    { "doc" : {"content" : "i think java is the best programming language"} }
    { "update": { "_id": "3"} }
    { "doc" : {"content" : "i am only an elasticsearch beginner"} }
    { "update": { "_id": "4"} }
    { "doc" : {"content" : "elasticsearch and hadoop are all very good solution, i am a beginner"} }
    { "update": { "_id": "5"} }
    { "doc" : {"content" : "spark is best big data solution based on scala ,an programming language similar to java"} }
    
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"follower_num" : 5} }
    { "update": { "_id": "2"} }
    { "doc" : {"follower_num" : 10} }
    { "update": { "_id": "3"} }
    { "doc" : {"follower_num" : 25} }
    { "update": { "_id": "4"} }
    { "doc" : {"follower_num" : 3} }
    { "update": { "_id": "5"} }
    { "doc" : {"follower_num" : 60} }
    
    
    GET /forum/article/_search
    {
      "query": {
        "function_score": {
          "query": {
            "multi_match": {
              "query": "java spark",
              "fields": ["tile", "content"]
            }
          },
          "field_value_factor": {
            "field": "follower_num",
            "modifier": "log1p",
            "factor": 0.5
          },
          "boost_mode": "sum",
          "max_boost": 2
        }
      }
    }
    POST /my_index/my_type/_bulk
    { "index": { "_id": 1 }}
    { "text": "Surprise me!"}
    { "index": { "_id": 2 }}
    { "text": "That was surprising."}
    { "index": { "_id": 3 }}
    { "text": "I wasn't surprised."}
    
    GET /my_index/my_type/_search 
    {
      "query": {
        "fuzzy": {
          "text":{
          "value": "surprize",
            "fuzziness": 10
          }
        }
      }
    }
    
    
    
    GET /my_index/my_type/_search 
    {
      "query": {
        "match": {
          "text": {
            "query": "SURPIZE ME",
            "fuzziness": "AUTO"
          }
        }
      }
    }
    GET /my_index/my_type/_search 
    {
      "query": {
        "match": {
         "text":{
           "query": "SURPIZE ME"
           , "fuzziness": "AUTO",
           "operator": "and"
         }
        }
      }
    }
    GET /my_index/_analyze
    {
      "text": "男子偷上万元发红包求交女友 被抓获时仍然单身",
      "analyzer": "ik_max_word"
    }
    
    GET /my_index/my_type/_search 
    {
      "query": {
        "match": {
          "text": "16岁少女结婚好还是单身好?"
        }
      }
    }
    
    PUT /my_index 
    {
      "mappings": {
        "my_type": {
          "properties": {
            "text": {
              "type": "text",
              "analyzer": "ik_max_word"
            }
          }
        }
      }
    }
    
    POST /my_index/my_type/_bulk
    { "index": { "_id": "1"} }
    { "text": "男子偷上万元发红包求交女友 被抓获时仍然单身" }
    { "index": { "_id": "2"} }
    { "text": "16岁少女为结婚“变”22岁 7年后想离婚被法院拒绝" }
    { "index": { "_id": "3"} }
    { "text": "深圳女孩骑车逆行撞奔驰 遭索赔被吓哭(图)" }
    { "index": { "_id": "4"} }
    { "text": "女人对护肤品比对男票好?网友神怼" }
    { "index": { "_id": "5"} }
    { "text": "为什么国内的街道招牌用的都是红黄配?" }
    
    
    DELETE my_index
    
    
    
    PUT /my_index 
    {
      "mappings": {
        "my_type": {
          "properties": {
            "text": {
              "type": "text",
              "analyzer": "ik_max_word"
            }
          }
        }
      }
    }
    POST /my_index/my_type/_bulk
    { "index": { "_id": "1"} }
    { "text": "男子偷上万元发红包求交女友 被抓获时仍然单身" }
    { "index": { "_id": "2"} }
    { "text": "16岁少女为结婚“变”22岁 7年后想离婚被法院拒绝" }
    { "index": { "_id": "3"} }
    { "text": "深圳女孩骑车逆行撞奔驰 遭索赔被吓哭(图)" }
    { "index": { "_id": "4"} }
    { "text": "女人对护肤品比对男票好?网友神怼" }
    { "index": { "_id": "5"} }
    { "text": "为什么国内的街道招牌用的都是红黄配?" }
    
    GET /my_index/my_type/_search 
    {
      "query": {
        "match": {
          "text": "16岁少女结婚好还是单身好?"
        }
      }
    }
    GET /my_index/_analyze
    {
      "text":"16岁少女结婚好还是单身好",
       "analyzer": "ik_max_word"
    }
    
    
    PUT /tvs
    {
        "mappings": {
            "sales": {
                "properties": {
                    "price": {
                        "type": "long"
                    },
                    "color": {
                        "type": "keyword"
                    },
                    "brand": {
                        "type": "keyword"
                    },
                    "sold_date": {
                        "type": "date"
                    }
                }
            }
        }
    }
    GET /tvs/sales/_search
    {
    "size": 0, 
      "aggs": {
        "popular_colors": {
         "terms": {
           "field": "color"
         }
        }
      }
    }
    GET /tvs/sales/_search
    {
       "size" : 0,
       "aggs": {
          "colors": {
             "terms": {
                "field": "color"
             },
             "aggs": { 
                "avg_price": { 
                   "avg": {
                      "field": "price" 
                   }
                }
             }
          }
       }
    }
    GET /tvs/sales/_search
    {
      "size": 0,
      "aggs": {
        "colors": {
         "terms": {
           "field": "color"
         },
         "aggs": {
           "avg_price": {
            "avg": {
              "field": "price"
            }
           }
         }
        }
      }
    }
    
    
    
    
    
    GET /tvs/sales/_search
    {
      "size": 0,
      "aggs": {
        "group_by_color": {
          "terms": {
            "field": "color"
          },
          "aggs": {
            "color_avg_price": {
              "avg": {
                "field": "price"
              }
            },
            "group_by_brand": {
              "terms": {
                "field": "brand"
              },
              "aggs": {
                "brand_avg_price": {
                  "avg": {
                    "field": "price"
                  }
                }
              }
            }
          }
        }
      }
    }
    GET /tvs/sales/_search 
    {
      "size": 0,
      "aggs": {
        "group_by_color": {
          "terms": {
            "field": "color"
          },
          "aggs": {
            "color_avg_price": {
              "avg": {
                "field": "price"
              }
            },
            "group_by_brand": {
              "terms": {
                "field": "brand"
              },
              "aggs": {
                "brand_avg_price": {
                  "avg": {
                    "field": "price"
                  }
                }
              }
            }
          }
        }
      }
    }
    GET /tvs/sales/_search
    {
      "size": 0,
      "aggs": {
        "colors": {
          "terms": {
            "field": "color"
          },
          "aggs": {
            "avg_price": {
              "avg": {
                "field": "price"
              }
            },
            "min_price": {
              "min": {
                "field": "price"
              }
            },
            "max_price": {
              "max": {
                "field": "price"
              }
            },
            "sum_price": {
              "sum": {
                "field": "price"
              }
            }
          }
        }
      }
    }
    GET /tvs/sales/_search
    {
      "size": 0, 
      "aggs": {
        "colors": {
         "terms": {
           "field": "color"
           
         },
         "aggs": {
           "avg_price": {
             "avg": {
               "field": "price"
             }
            },
            "max_price":{
              "max": {
                "field": "price"
              }
            },
            "min_price":{
              "min": {
                "field": "price"
              }
            },
            "sum_price":{
              "sum": {
                "field": "price"
              }
            }
         }
        }
      }
    }
    
    GET /tvs/sales/_search
    {
       "size" : 0,
       "aggs":{
          "price":{
             "histogram":{ 
                "field": "price",
                "interval": 2000
             },
             "aggs":{
                "revenue": {
                   "sum": { 
                     "field" : "price"
                   }
                 }
             }
          }
       }
    }
    GET /tvs/sales/_search
    {
      "size": 0,
      "aggs": {
        "price": {
          "histogram": {
            "field": "price",
            "interval": 2000
          },
          "aggs": {
            "revenue":{
              "sum": {
                "field": "price"
              }
            }
          }
        }
      }
    }
    GET /tvs/sales/_search
    {
      "size": 0,
      "aggs": {
        "sales": {
         "date_histogram": {
           "field": "date",
           "interval": "month",
           "format": "yyyy-MM-dd",
           "min_doc_count": 0,
           "extended_bounds":{
               "min" : "2016-01-01",
                "max" : "2017-12-31"
           }
         }
        }
      }
    }
    
    GET /tvs/sales/_search 
    {
      "size": 0,
      "aggs": {
        "group_by_sold_date": {
          "date_histogram": {
            "field": "sold_date",
            "interval": "quarter",
            "format": "yyyy-MM-dd",
            "min_doc_count": 0,
            "extended_bounds": {
              "min": "2016-01-01",
              "max": "2017-12-31"
            }
          },
          "aggs": {
            "group_by_brand": {
              "terms": {
                "field": "brand"
              },
              "aggs": {
                "sum_price": {
                  "sum": {
                    "field": "price"
                  }
                }
              }
            },
            "total_sum_price": {
              "sum": {
                "field": "price"
              }
            }
          }
        }
      }
    }
    
    GET /tvs/sales/_search 
    {
      "size":0,
      "aggs": {
        "group_by_sold_date": {
        "date_histogram": {
          "field": "date",
          "interval": "quarter",
          "min_doc_count": 0,
          "extended_bounds":{
            "min": "2016-01-01",
              "max": "2017-12-31"
          }
        }, 
        "aggs": {
          "group_by_brand": {
           "terms": {
             "field": "brand"
           },
           "aggs": {
             "sum_price": {
               "sum": {
                 "field": "price"
               }
             }
           }
          },
          "total_price":{
            "sum": {
              "field": "price"
            }
          }
        }
        }
      }
    }
    GET /tvs/sales/_search 
    {
      "size": 0, 
      "query": {
        "constant_score": {
          "filter": {
            "range": {
              "price": {
                "gte": 1200
              }
            }
          }
        }
      },
      "aggs": {
        "avg_price": {
          "avg": {
            "field": "price"
          }
        }
      }
    }
    
    GET /tvs/sales/_search
    {
      "size" : 0,
      "aggs" : {
          "months" : {
            "date_histogram": {
              "field": "sold_date",
              "interval": "month"
            },
            "aggs": {
              "distinct_colors" : {
                  "cardinality" : {
                    "field" : "brand"
                  }
              }
            }
          }
      }
    }
    #qu'chong去重 
    GET /tvs/sales/_search
    {
      "aggs": {
        "months": {
          "date_histogram": {
            "field": "sold_date",
            "interval": "month"
          
          },
          "aggs": {
            "distinct_colors": {
             "cardinality": {
               "field": "brand",
               "precision_threshold": 100
             }
            }
          }
        }
      }
    }
    
    
    
    POST /website/logs/_bulk
    { "index": {}}
    { "latency" : 105, "province" : "江苏", "timestamp" : "2016-10-28" }
    { "index": {}}
    { "latency" : 83, "province" : "江苏", "timestamp" : "2016-10-29" }
    { "index": {}}
    { "latency" : 92, "province" : "江苏", "timestamp" : "2016-10-29" }
    { "index": {}}
    { "latency" : 112, "province" : "江苏", "timestamp" : "2016-10-28" }
    { "index": {}}
    { "latency" : 68, "province" : "江苏", "timestamp" : "2016-10-28" }
    { "index": {}}
    { "latency" : 76, "province" : "江苏", "timestamp" : "2016-10-29" }
    { "index": {}}
    { "latency" : 101, "province" : "新疆", "timestamp" : "2016-10-28" }
    { "index": {}}
    { "latency" : 275, "province" : "新疆", "timestamp" : "2016-10-29" }
    { "index": {}}
    { "latency" : 166, "province" : "新疆", "timestamp" : "2016-10-29" }
    { "index": {}}
    { "latency" : 654, "province" : "新疆", "timestamp" : "2016-10-28" }
    { "index": {}}
    { "latency" : 389, "province" : "新疆", "timestamp" : "2016-10-28" }
    { "index": {}}
    { "latency" : 302, "province" : "新疆", "timestamp" : "2016-10-29" }
    
    
    
    PUT /website
    {
        "mappings": {
            "logs": {
                "properties": {
                    "latency": {
                        "type": "long"
                    },
                    "province": {
                        "type": "keyword"
                    },
                    "timestamp": {
                        "type": "date"
                    }
                }
            }
        }
    }
    
    GET website/_search
    {
       "size": 0,
      "aggs": {
        "latency_time": {
          "percentiles": {
            "field": "latency",
            "percents": [
              50,
              75,
              99
            ]
          }
        },
        "avg_time": {
          "avg": {
            "field": "latency"
          }
        }
      }
    }
    GET /website/logs/_search 
    {
      "size": 0,
      "aggs": {
        "latency_percentiles": {
          "percentiles": {
            "field": "latency",
            "percents": [
              50,
              95,
              99
            ]
          }
        },
        "latency_avg": {
          "avg": {
            "field": "latency"
          }
        }
      }
    }
    
    GET /website/logs/_search 
    {
      "size": 0,
      "aggs": {
        "group_by_province": {
          "terms": {
            "field": "province"
          },
          "aggs": {
            "latency_percentile_ranks": {
              "percentile_ranks": {
                "field": "latency",
                "values": [
                  200,
                  1000
                ]
              }
            }
          }
        }
      }
    }
    
    
    
    GET /_stats/fielddata?fields=*
    
    GET /_nodes/stats/indices/fielddata?fields=*
    
    GET /_nodes/stats/indices/fielddata?level=indices&fields=*
    
    
    
    POST /test_index/_mapping/test_type
    {
      "properties": {
        "test_field": {
          "type": "string",
          "fielddata": {
            "loading" : "eager_global_ordinals" 
          }
        }
      }
    }
    
    POST /test_index/_mapping/test_type
    {
      "properties": {
        "test_field": {
          "type": "string",
          "fielddata": {
            "loading" : "eager" 
          }
        }
      }
    }
    PUT /website/users/1 
    {
      "name":     "小鱼儿",
      "email":    "xiaoyuer@sina.com",
      "birthday":      "1980-01-01"
    }
    
    PUT /website/blogs/1
    {
      "title":    "我的第一篇博客",
      "content":     "这是我的第一篇博客,开通啦!!",
      "userId":     1 
    }
    
    GET website/blogs/_search
    GET /website/users/_search 
    {
      "query": {
        "term": {
          "name.keyword": {
            "value": "小鱼儿"
          }
        }
      }
    }
    
    GET /website/blogs/_search 
    {
      "query": {
        "constant_score": {
          "filter": {
            "terms": {
              "userId": [
                1
              ]
            }
          }
        }
      }
    }
    GET /website/blogs/_search 
    {
      
      "query": {
        "constant_score": {
          "filter": {
            "terms": {
              "userId": [
                1
              ]
            }
          }
        }
      }
    }
    DELETE website
    
    
    PUT  website/users/1
    {
      "name":"小鱼儿",
      "email":"xiaoyuer@sina.com",
      "birthday":"1989-01-01"
    }
    PUT  website/blogs/1
    {
      "title":"小鱼儿的第一篇博客",
      "ontent":"大家好,我是小鱼儿。。。",
      "userInfo":{
        "userId":1,
        "userName":"小鱼儿"
      }
    }
    GET /website/blogs/_search 
    {
      "query": {
        "term": {
          "userInfo.userName.keyword": {
            "value": "小鱼儿"
          }
        }
      }
    }
    
    PUT /website/users/3
    {
      "name": "黄药师",
      "email": "huangyaoshi@sina.com",
      "birthday": "1970-10-24"
    }
    
    PUT /website/blogs/3
    {
      "title": "我是黄药师",
      "content": "我是黄药师啊,各位同学们!!!",
      "userInfo": {
        "userId": 1,
        "userName": "黄药师"
      }
    }
    
    PUT /website/users/2
    {
      "name": "花无缺",
      "email": "huawuque@sina.com",
      "birthday": "1980-02-02"
    }
    
    PUT /website/blogs/4
    {
      "title": "花无缺的身世揭秘",
      "content": "大家好,我是花无缺,所以我的身世是。。。",
      "userInfo": {
        "userId": 2,
        "userName": "花无缺"
      }
    }
    
    
    GET /website/blogs/_search 
    {
      "size": 0,
      "aggs": {
        "group_by_name": {
        "terms": {
          "field": "userInfo.userName.keyword"
         },
         "aggs": {
           "top_blogs": {
             "top_hits": {
              "_source": {
                "include": "title"
              },
              "size": 5
             }
           }
         }
        }
      }
    }
    
    GET /website/blogs/_search 
    {
      "size": 0, 
      "aggs": {
        "group_by_username": {
          "terms": {
            "field": "userInfo.userName.keyword"
          },
          "aggs": {
            "top_blogs": {
              "top_hits": {
                "_source": {
                  "include": "title"
                }, 
                "size": 5
              }
            }
          }
        }
      }
    }
    
    DELETE /fs/lock/global
    
    
    
    POST /fs/file/1/_update
    {
      "doc": {
        "name": "README1.txt"
      }
    }
    DELETE /fs/lock/global
    
    
    
    PUT /website/blogs/6
    {
      "title": "花无缺发表的一篇帖子",
      "content":  "我是花无缺,大家要不要考虑一下投资房产和买股票的事情啊。。。",
      "tags":  [ "投资", "理财" ],
      "comments": [ 
        {
          "name":    "小鱼儿",
          "comment": "什么股票啊?推荐一下呗",
          "age":     28,
          "stars":   4,
          "date":    "2016-09-01"
        },
        {
          "name":    "黄药师",
          "comment": "我喜欢投资房产,风,险大收益也大",
          "age":     31,
          "stars":   5,
          "date":    "2016-10-22"
        }
      ]
    }
    
    GET /website/blogs/_search
    {
      "query": {
        "bool": {
          "must": [
            { "match": { "comments.name": "黄药师" }},
            { "match": { "comments.age":  28      }} 
          ]
        }
      }
    }
    
    PUT /website
    {
      "mappings": {
        "blogs": {
          "properties": {
            "comments": {
              "type": "nested", 
              "properties": {
                "name":    { "type": "string"  },
                "comment": { "type": "string"  },
                "age":     { "type": "short"   },
                "stars":   { "type": "short"   },
                "date":    { "type": "date"    }
              }
            }
          }
        }
      }
    }
    
    PUT /website/blogs/1
    {
      "title": "花无缺发表的一篇帖子",
      "content":  "我是花无缺,大家要不要考虑一下投资房产和买股票的事情啊。。。",
      "tags":  [ "投资", "理财" ],
      "comments": [ 
        {
          "name":    "小鱼儿",
          "comment": "什么股票啊?推荐一下呗",
          "age":     28,
          "stars":   4,
          "date":    "2016-09-01"
        },
        {
          "name":    "黄药师",
          "comment": "我喜欢投资房产,风,险大收益也大",
          "age":     31,
          "stars":   5,
          "date":    "2016-10-22"
        }
      ]
    }
    GET /website/blogs/_search
    
    
    GET /website/blogs/_search
    {
      "query": {
        "bool": {
          "must": [
            { "match": { "comments.name": "黄药师" }},
            { "match": { "comments.age":  31      }} 
          ]
        }
      }
    }
    GET /website/blogs/_search
    {
      "query": {
        "bool": {
          "must": [
            {
              "match": {
                "title": "花无缺"
              },
              "nested": {
                "path": "comments",
                "query": {
                  "bool": {
                    "must": [
                      {
                        "match": {
                          "comments.name":"黄药师"
                        }
                      }
                    ]
                  }
                }
              }
            }
          ]
        }
      }
    }
    
    GET /website/blogs/_search 
    {
      "query": {
        "bool": {
          "must": [
            {
              "match": {
                "title": "花无缺"
              }
            },
            {
              "nested": {
                "path": "comments",
                "query": {
                  "bool": {
                    "must": [
                      {
                        "match": {
                          "comments.name": "黄药师"
                        }
                      },
                      {
                        "match": {
                          "comments.age": 31
                        }
                      }
                    ]
                  }
                }
              }
            }
          ]
        }
      }
    }
    
    GET /website/blogs/_search 
    {
      "size": 0, 
      "aggs": {
        "comments_path": {
          "nested": {
            "path": "comments"
          }, 
          "aggs": {
            "group_by_comments_date": {
              "date_histogram": {
                "field": "comments.date",
                "interval": "month",
                "format": "yyyy-MM"
              },
              "aggs": {
                "avg_stars": {
                  "avg": {
                    "field": "comments.stars"
                  }
                }
              }
            }
          }
        }
      }
    }
    GET /website/blogs/_search 
    {
      "size": 0,
      "aggs": {
        "comments_path": {
          "nested": {
            "path": "comments"
          },
          "aggs": {
            "group_by_comments_age": {
              "histogram": {
                "field": "comments.age",
                "interval": 10
              },
              "aggs": {
                "reverse_path": {
                  "reverse_nested": {}, 
                  "aggs": {
                    "group_by_tags": {
                      "terms": {
                        "field": "tags.keyword"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    
    DELETE company
    
    GET /company/_search
    PUT /company
    {
      "mappings": {
        "rd_center": {},
        "employee": {
          "_parent": {
            "type": "rd_center" 
          }
        }
      }
    }
    
    POST /company/rd_center/_bulk
    { "index": { "_id": "1" }}
    { "name": "北京研发总部", "city": "北京", "country": "中国" }
    { "index": { "_id": "2" }}
    { "name": "上海研发中心", "city": "上海", "country": "中国" }
    { "index": { "_id": "3" }}
    { "name": "硅谷人工智能实验室", "city": "硅谷", "country": "美国" }
    
    
    PUT /company/employee/1?parent=1 
    {
      "name":  "张三",
      "birthday":   "1970-10-24",
      "hobby": "爬山"
    }
    
    
    
    
    POST /company/employee/_bulk
    { "index": { "_id": 2, "parent": "1" }}
    { "name": "李四", "birthday": "1982-05-16", "hobby": "游泳" }
    { "index": { "_id": 3, "parent": "2" }}
    { "name": "王二", "birthday": "1979-04-01", "hobby": "爬山" }
    { "index": { "_id": 4, "parent": "3" }}
    { "name": "赵五", "birthday": "1987-05-11", "hobby": "骑马" }
    GET /company/rd_center/_search
    {
      "query": {
        "has_child": {
          "type": "employee",
          "query": {
            "range": {
              "birthday": {
                "gte": "1980-01-01"
              }
            }
          }
        }
      }
    }
    
    GET /company/rd_center/_search
    {
      "query": {
        "has_child": {
          "type": "employee",
          "query": {
            "range": {
              "birthday": {
                "gte": "1980-01-01"
              }
            }
          }
        }
      }
    }
    GET /company/rd_center/_search
    {
      "query": {
        "has_child": {
          "type": "employee",
          "query": {
            "match": {
              "name": "张三"
            }
          }
        }
      }
    }
    
    GET /company/rd_center/_search
    {
      "query": {
        "has_child": {
          "type": "employee",
          "min_children": 2, 
          "query": {
            "match_all": {}
          }
        }
      }
    }
    GET /company/employee/_search 
    {
      "query": {
        "has_parent": {
          "parent_type": "rd_center",
          "query": {
            "term": {
              "country.keyword":"中国"
            }
          }
        }
      }
    }
    GET /company/rd_center/_search 
    {
      "size": 0,
      "aggs": {
        "group_by_country": {
          "terms": {
            "field": "country.keyword"
          },
          "aggs": {
            "group_by_child_employee": {
              "children": {
                "type": "employee"
              },
              "aggs": {
                "group_by_hobby": {
                  "terms": {
                    "field": "hobby.keyword"
                  }
                }
              }
            }
          }
        }
      }
    }
    GET /company/rd_center/_search 
    {
      "aggs": {
        "group_by_country": {
          "terms": {
            "field": "country.keyword"
          },
          "aggs": {
            "group_by_child_employee": {
            "children": {
              "type": "employee"
            },
            "aggs": {
              "group_by_hobby": {
               "terms": {
                 "field": "hobby.keyword"
                
               }
              }
            }
            }
          }
        }
      }
    }
    
    DELETE company
    PUT /company
    {
      "mappings": {
        "country": {},
        "rd_center": {
          "_parent": {
            "type": "country" 
          }
        },
        "employee": {
          "_parent": {
            "type": "rd_center" 
          }
        }
      }
    }
    
    POST /company/country/_bulk
    { "index": { "_id": "1" }}
    { "name": "中国" }
    { "index": { "_id": "2" }}
    { "name": "美国" }
    
    
    POST /company/rd_center/_bulk
    { "index": { "_id": "1", "parent": "1" }}
    { "name": "北京研发总部" }
    { "index": { "_id": "2", "parent": "1" }}
    { "name": "上海研发中心" }
    { "index": { "_id": "3", "parent": "2" }}
    { "name": "硅谷人工智能实验室" }
    
    
    PUT /company/employee/1?parent=1&routing=1
    {
      "name":  "张三",
      "dob":   "1970-10-24",
      "hobby": "爬山"
    }
    
    
    GET /company/country/_search
    {
      "query": {
        "has_child": {
          "type": "rd_center",
          "query": {
            "has_child": {
              "type": "employee",
              "query": {
                "match": {
                  "hobby": "爬山"
                }
              }
            }
          }
        }
      }
    }
    GET /company/country/_search
    {
      "query": {
        "has_child": {
          "type": "rd_center",
          "query": {
            "has_child": {
              "type": "employee",
              "query": {
                "match": {
                  "hobby": "爬山"
                }
              }
            }
          }
        }
      }
    }
    DELETE blog_website
    PUT /blog_website
    {
      "mappings": {
        "blogs": {
          "properties": {
            "title": {
              "type": "text",
              "analyzer": "ik_max_word"
            },
            "content": {
              "type": "text",
              "analyzer": "ik_max_word"
            }
          }
        }
      }
    }
    
    PUT /blog_website/blogs/1
    {
      "title": "我的第一篇博客",
      "content": "大家好,这是我写的第一篇博客,特别喜欢这个博客网站!!!"
    }
    GET blog_website/blogs/_search
    {
      "query": {
        "match": {
          "title": "博客"
        }
      
      },
      "highlight": {
        "fields": {
          "title":{}
        }
      }
    }
    
    
    GET /blog_website/blogs/_search 
    {
      "query": {
        "bool": {
          "should": [
            {
              "match": {
                "title": "博客"
              }
            },{
              "match": {
                "content": "博客"
              }
            }
          ]
        }
        
      },
      "highlight": {
        "fields": {
          "title":{},
          "content":{}
        }
      }
    }
    GET /blog_website/blogs/_search/template
    {
      "inline":{
        "query":{
        "match":{
          "{{field}}":"{{value}}"
        }
      }
      },"params": {
        "field":"title",
        "value":"博客"
      }
    }
    
    
    GET /blog_website/blogs/_search/template
    {
      "inline": "{"query": {"match": {{#toJson}}matchCondition{{/toJson}}}}",
      "params": {
        "matchCondition": {
          "title": "博客"
        }
      }
    }
    GET /blog_website/blogs/_search/template
    {
      "inline": {
        "query": {
          "match": {
            "title": "{{#join delimiter=' '}}titles{{/join delimiter=' '}}"
          }
        }
      },
      "params": {
        "titles": ["博客", "网站"]
      }
    }
    
    #  delete news_website
    
    
    
    PUT /news_website
    {
      "mappings": {
        "news" : {
          "properties" : {
            "title" : {
              "type": "text",
              "analyzer": "ik_max_word",
              "fields": {
                "suggest" : {
                  "type" : "completion",
                  "analyzer": "ik_max_word"
                }
              }
            },
            "content": {
              "type": "text",
              "analyzer": "ik_max_word"
            }
          }
        }
      }
    }
    
    PUT /news_website/news/1
    {
      "title": "大话西游电影",
      "content": "大话西游的电影时隔20年即将在2017年4月重映"
    }
    PUT /news_website/news/2
    {
      "title": "大话西游小说",
      "content": "某知名网络小说作家已经完成了大话西游同名小说的出版"
    }
    PUT /news_website/news/3
    {
      "title": "大话西游手游",
      "content": "网易游戏近日出品了大话西游经典IP的手游,正在火爆内测中"
    }
    PUT /news_website
    {
      "mappings": {
        "news" : {
          "properties" : {
            "title" : {
              "type": "text",
              "analyzer": "ik_max_word",
              "fields": {
                "suggest" : {
                  "type" : "completion",
                  "analyzer": "ik_max_word"
                }
              }
            },
            "content": {
              "type": "text",
              "analyzer": "ik_max_word"
            }
          }
        }
      }
    }
    PUT /news_website2
    {
      "mappings": {
        "news":{
          "properties": {
            "title":{
              "type": "text",
              "analyzer": "ik_max_word",
              "fields": {
                "suggest":{
                  "type": "completion",
                  "analyzer": "ik_max_word"
                }
              }
            },
            "content":{
              "type": "text",
              "analyzer": "ik_max_word",
              "fields": {
                "suggest":{
                  "type": "completion",
                  "analyzer": "ik_max_word"
                }
              }
            }
          }
        }
      }
    }
    POST /news_website2/news/3
    {
    "title": "大话西游电影",
      "content": "大话西游的电影时隔20年即将在2017年4月重映"
    }
    GET /news_website2/news/_search
    {
      "query": {
        "match": {
          "title": "西游"
        }
      },
      "explain": true
    }
    
    
    GET /news_website2/news/_search
    {
      "suggest":{
        "suggest":{
          "prefix":"大话西游",
          "completion":{
            "field":"title.suggest"
          }
        }
      }
    }
    
    #
    GET /news_website/news/_search
    {
      "query": {
        "prefix": {
          "title": {
            "value": "大话西游"
          }
        }
      },
      "_source": ["title","content"],
      "explain": true
    }
    
    GET /news_website/news/_search
    {
      "suggest": {
        "my-suggest" : {
          "prefix" : "大话西游",
          "completion" : {
            "field" : "title.suggest"
          }
        }
      }
    }
    DELETE my_index
    PUT my_index
    {
      "mappings": {
        "my_type": {
          "dynamic_templates": [
            {
              "integers": {
                "match_mapping_type": "long",
                "mapping": {
                  "type": "integer"
                }
              }
            },
            {
              "strings": {
                "match_mapping_type": "string",
                "mapping": {
                  "type": "text",
                  "fields": {
                    "raw": {
                      "type": "keyword",
                      "ignore_above": 500
                    }
                  }
                }
              }
            }
          ]
        }
      }
    }
    
    PUT /my_index/my_type/1
    {
      "test_long": 1,
      "test_string": "hello world"
    }
    
    
    GET my_index/_mapping/my_type
    
    PUT /my_index 
    {
      "mappings": {
        "my_type": {
          "dynamic_templates": [
            {
              "string_as_integer": {
                "match_mapping_type": "string",
                "match": "long_*",
                "unmatch": "*_text",
                "mapping": {
                  "type": "integer"
                }
              }
            }
          ]
        }
      }
    }
    
    DELETE car_shop
    PUT /car_shop
    {
        "mappings": {
            "cars": {
                "properties": {
                    "brand": {
                        "type": "text",
                        "analyzer": "ik_max_word",
                        "fields": {
                            "raw": {
                                "type": "keyword"
                            }
                        }
                    },
                    "name": {
                        "type": "text",
                        "analyzer": "ik_max_word",
                        "fields": {
                            "raw": {
                                "type": "keyword"
                            }
                        }
                    }
                }
            }
        }
    }
    
    GET car_shop/_search
    
    
    PUT /car_shop/cars/2
    {
        "brand": "奔驰",
        "name": "奔驰C200",
        "price": 350000,
        "produce_date": "2017-01-05"
    }
    
    
    
    PUT /car_shop/sales/1
    {
        "brand": "宝马",
        "name": "宝马320",
        "price": 320000,
        "produce_date": "2017-01-01",
        "sale_price": 300000,
        "sale_date": "2017-01-21"
    }
    
    PUT /car_shop/sales/2
    {
        "brand": "宝马",
        "name": "宝马320",
        "price": 320000,
        "produce_date": "2017-01-01",
        "sale_price": 300000,
        "sale_date": "2017-01-21"
    }
    
    
    GET /car_shop/sales/_search
    
    DELETE products
    
    PUT products
    {
      "settings": {
        "number_of_shards": 1
      }
    }
    
    
    
    POST /products/products/_bulk
    { "index": { "_id": 1 }}
    { "productID" : "XHDK-A-1293-#fJ3","desc":"iPhone" }
    { "index": { "_id": 2 }}
    { "productID" : "KDKE-B-9947-#kL5","desc":"iPad" }
    { "index": { "_id": 3 }}
    { "productID" : "JODL-X-1937-#pV7","desc":"MBP" }
    POST _analyze
    {
      "text":"iPhone"
    }
    
    
    GET /products/products/_search
    {
      "query": {
       "term": {
         "desc.keyword": {
           "value": "iPhone"
         }
       }
      }
    }
    GET /products/products/_search
    {
      "explain": true, 
      "query": {
        "constant_score": {
          "filter": {
            "term": {
              "desc.keyword": "iPhone"
            }
          }
         
        }
      }
    }
    
    
    
    
    
    
    PUT /website 
    {
      "mappings": {
        "article": {
          "properties": {
            "title": {
              "type": "text",
              "fields": {
                "raw": {
                  "type": "string",
                  "index": "not_analyzed"
                }
              },
              "fielddata": true
            },
            "content": {
              "type": "text"
            },
            "post_date": {
              "type": "date"
            },
            "author_id": {
              "type": "long"
            }
          }
        }
      }
    }
    
    PUT /blogs/blogs/1
    {
        "title": "Quick brown rabbits",
        "body":  "Brown rabbits are commonly see."
    }
    
    
    PUT /blogs/blogs/2
    {
        "title": "Keeping pets healthy",
        "body":  "My quick brown fox eats rabbits on a regular basis."
    }
    
    POST /blogs/blogs/_search
    {
      "query": {
        "bool": {
          "should": [
            {
              "match": {
                "title": "Brown fox"
              }
            },
            {
              "match": {
                "body": "Brown fox"
              }
            }
          ]
        }
      }
    }
    
    GET /blogs/blogs/_search
    {
      "query": {
        "dis_max": {
          "tie_breaker": 0.7,
          "boost": 1.2,
          "queries": [
            {
              "match": {
                "title": "Brown fox"
              }
            },
            {
              "match": {
                "body": "Brown fox"
              }
            }
          ]
        }
      }
    }
    POST blogs/blogs/_search
    {
        "query": {
            "dis_max": {
                "queries": [
                    { "match": { "title": "Quick pets" }},
                    { "match": { "body":  "Quick pets" }}
                ],
                "tie_breaker": 0.2
            }
        }
    }
    GET articles/_search
    DELETE articles
    
    PUT articles
    {
      "mappings": {
         "articles"{
         "properties": {
          "title_completion":{
            "type": "completion"
          }
         } 
        }
      }
    }
    
    PUT /articles 
    {
      "mappings": {
        "articles": {
          "properties": {
          "title_completion":{
            "type": "completion"
          }
         } 
        }
      }
    }
    
    POST articles/articles/_bulk
    { "index" : { } }
    { "title_completion": "lucene is very cool"}
    { "index" : { } }
    { "title_completion": "Elasticsearch builds on top of lucene"}
    { "index" : { } }
    { "title_completion": "Elasticsearch rocks"}
    { "index" : { } }
    { "title_completion": "elastic is the company behind ELK stack"}
    { "index" : { } }
    { "title_completion": "Elk stack rocks"}
    { "index" : {} }
    
    POST articles/_search?pretty
    {
      "size": 0,
      "suggest": {
        "article-suggester": {
          "prefix": "e ",
          "completion": {
            "field": "title_completion"
          }
        }
      }
    }
    GET articles/articles/_search
    {
      "explain": true, 
      "suggest":{
        "articles-suggest":{
          "prefix":"elk",
          "completion":{
            "field":"title_completion"
          }
        }
      }
    }
    
    
    PUT /articles 
    {
      "mappings": {
        "articles": {
          "properties": {
          "title_completion":{
            "type": "completion"
          }
         } 
        }
      }
    }
    DELETE comments
    PUT comments
    PUT comments/_mapping
    
    
    PUT comments
    {
      "mappings": {
        "comments":{
           "properties": {
        "comment_autocomplete":{
          "type": "completion",
          "contexts":[{
            "type":"category",
            "name":"comment_category"
          }]
        }
      }
        }
      }
    }
    DELETE comments
    
    
    GET comments/_search
    
    PUT comments
    {
      "mappings": {
        "comments": {
          "properties": {
            "comment_autocomplete": {
              "type": "completion",
              "contexts": [
                {
                  "type": "category",
                  "name": "comment_category"
                }
              ]
            }
          }
        }
      }
    }
    
    
    
    POST comments/comments/1
    {
      "comment":"I love the star war movies",
      "comment_autocomplete":{
        "input":["star wars"],
        "contexts":{
          "comment_category":"movies"
        }
      }
    }
    POST comments/comments/2
    {
      "comment":"Where can I find a Starbucks",
      "comment_autocomplete":{
        "input":["starbucks"],
        "contexts":{
          "comment_category":"coffee"
        }
      }
    }
    GET comments/_search
    {
      "size": 0, 
      "suggest": {
        "my_suggest": {
          "prefix": "sta",
          "completion":{
            "field":"comment_autocomplete",
            "contexts":{
              "comment_category":"movies"
            }
          }
        }
      }
    }
    
    GET comments/_search
    {
      "size": 0, 
      "suggest": {
        "my_suggest": {
          "prefix": "sta",
          "completion":{
            "field":"comment_autocomplete",
            "contexts":{
              "comment_category":"coffee"
            }
          }
        }
      }
    }
    
    
    
    
    
    
    
    
    
    
    GET /_cat/health?v
    
    GET _cluster/health
    
    GET /_cat/indices?v
    
    
    GET /_cat/nodes?v
    
    get cars/_search
    
    
    put car
    
    POST /car/transactions/_bulk
    { "index": {}}
    { "price" : 10000, "color" : "red", "make" : "honda", "sold" : "2014-10-28" }
    { "index": {}}
    { "price" : 20000, "color" : "red", "make" : "honda", "sold" : "2014-11-05" }
    { "index": {}}
    { "price" : 30000, "color" : "green", "make" : "ford", "sold" : "2014-05-18" }
    { "index": {}}
    { "price" : 15000, "color" : "blue", "make" : "toyota", "sold" : "2014-07-02" }
    { "index": {}}
    { "price" : 12000, "color" : "green", "make" : "toyota", "sold" : "2014-08-19" }
    { "index": {}}
    { "price" : 20000, "color" : "red", "make" : "honda", "sold" : "2014-11-05" }
    { "index": {}}
    { "price" : 80000, "color" : "red", "make" : "bmw", "sold" : "2014-01-01" }
    { "index": {}}
    { "price" : 25000, "color" : "blue", "make" : "ford", "sold" : "2014-02-12" }
    
    #an'yan'se'fen'zu安颜色分组
    
    GET /car/transactions/_search
    {
       "size": 0,
      "aggs": {
        "group_by_color": {
         "terms": {
           "field": "color.keyword"
         }
        }
      }
    }
    
    
    #先按颜色分组后计算平均价格 
    GET /car/transactions/_search
    {
      "size": 0, 
      "aggs": {
        "group_by_color": {
          "terms": {
           "field": "color.keyword"
         },
         "aggs": {
           "avg_color": {
            "avg": {
              "field": "price"
            }
           }
         }
        }
        
      }
    }
    #select color, count(color) as cnt, avg(price) as avg_price from cars group by color order by cnt desc;
    
    
    #统计每种颜色汽车制造商的分布dsl实现
    GET /car/transactions/_search
    {
      "size": 0,
      "aggs": {
        "group_by_color": {
          "terms": {
            "field": "color.keyword"
          },
          "aggs": {
            "group_by_make": {
              "terms": {
                "field": "make.keyword"
              }
            }
          }
        }
      }
    }
    
    GET _stats/fielddata?human&fields=my_join_field
    
    GET _nodes/stats/indices/fielddata?human&fields=my_join_field
    GET /forum/article/_search
    {
        "query": {
            "match_phrase": {
                "title": {
                    "query": "java spark",
                    "slop":  1
                }
            }
        }
    }
    
    
    GET /forum/article/_search
    {
      "query": {
        "match_phrase": {
          "content": {
            "query": "spark data",
            "slop": 3
          }
        }
      }
    }
    
    
    GET /forum/article/_search
    {
      "query": {
        "match_phrase": {
          "content": {
            "query": "data spark",
            "slop": 5
          }
        }
      }
    }
    #索引1的分片移动到索引2
    
    POST /_cluster/reroute
    {
      "commands": [
        {
          "move": {
            "index": "my_index_name",
            "shard": 0,
            "from_node": "node1",
            "to_node": "node2"
          }
        },
        {
          "allocate": {
            "index": "my_index_name",
            "shard": 1,
            "node": "node3"
          }
        }
      ]
    }
    #动态更新最小节点数。
    
    
    PUT /_cluster/settings
    {
      "persistent": {
        "discovery.zen.minimum_master_nodes": 3
      }
    }
    
    GET /forum/article/_search
    {
      "query": {
        "match_phrase": {
          "content": {
            "query": "java best",
            "slop": 15
          }
        }
      }
    }
    
    
    GET /books/_search
    {
      "query": {
        "constant_score": {
          "filter": {
            "range": {
              "price": {
                "gte": 20,
                "lt": 40
              }
            }
          }
        }
      }
    }
    
    
    
    GET /books/_search
    {
      "query": {
        "constant_score": {
          "filter": {
            "exists": {
              "field": "title"
            }
          }
        }
      }
    }
    
    GET /books/_search
    {
      "query": {
        "constant_score": {
          "filter": {
            "bool": {
              "should": [
                {
                  "range": {
                    "price": {
                      "gte": 20,
                      "lte": 40
                    }
                  }
                }
              ]
            }
          },
          "boost": 1.2
        }
      }
    }
    POST /books/_search
    {
      "query": {
        "match": {
          "title": "Java"
        }
      },
      "size": 2,
      "from": 0,
      "_source": [
        "title",
        "language",
        "author"
      ],
      "highlight": {
        "fields": {
          "title": {}
        }
      }
    }
    
    POST ik_index/ik_type/3
    {
      "title":"公路局正在治理解放大道路面积水问题"
    }
    
    GET ik_index/ik_type/_search
    {
      "query": {
        "match_phrase": {
          "title": "道路"
        }
      }
    }
    
    
    GET cars/_search
    
    
    
    
    
    GET ik_index/ik_type/_search
    {
      "profile": "true",
      "query": {
        "match_phrase": {
          "title.ik_my_max": "道路"
        }
      }
    }
    GET /_analyze
    {
      "analyzer": "ik_max_word", 
    "text":"公路局正在治理解放大道路面积水问题"
    }
    
    
    PUT /my_index
    {
        "settings": {
            "analysis": {
                "filter": {
                    "autocomplete_filter": { 
                        "type":     "edge_ngram",
                        "min_gram": 1,
                        "max_gram": 20
                    }
                },
                "analyzer": {
                    "autocomplete": {
                        "type":      "custom",
                        "tokenizer": "standard",
                        "filter": [
                            "lowercase",
                            "autocomplete_filter" 
                        ]
                    }
                }
            }
        }
    }
    
    GET /my_index/_analyze
    {
      "analyzer": "autocomplete",
      "text": "quick brown"
    }
    
    PUT /my_index/_mapping/my_type
    {
      "properties": {
          "title": {
              "type":     "string",
              "analyzer": "autocomplete",
              "search_analyzer": "standard"
          }
      }
    }
    
    
    
    
    GET /my_index/my_type/_search 
    {
      "query": {
        "match_phrase": {
          "title": "hello w"
        }
      }
    }
    
    PUT my_index
    {
      "mappings": {
        "my_type": {
          "properties": {
            "title": {
              "type": "keyword"
            }
          }
        }
      }
    }
    
    GET my_index/my_type/_search
    {
      "query": {
        "prefix": {
          "title": {
            "value": "C3"
          }
        }
      }
    }
    
    GET /forum/article/_search
    {
      "query": {
        "match_phrase": {
          "content": {
            "query": "spark data",
            "slop": 3
          }
        }
      }
    }GET /forum/article/_search
    {
        "query": {
            "match_phrase": {
                "title": {
                    "query": "java spark",
                    "slop":  1
                }
            }
        }
    }
    
    
    POST /forum/article/5/_update
    {
      "doc": {
        "content": "spark is best big data solution based on scala ,an programming language similar to java spark"
      }
    }
    
    GET _analyze
    {
      "text": "hello world, java spark",
      "analyzer": "standard"
    }
    
    PUT /forum/_mapping/article
    {
      "properties": {
          "new_author_first_name": {
              "type":     "string",
              "copy_to":  "new_author_full_name" 
          },
          "new_author_last_name": {
              "type":     "string",
              "copy_to":  "new_author_full_name" 
          },
          "new_author_full_name": {
              "type":     "string"
          }
      }
    }
    
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"new_author_first_name" : "Peter", "new_author_last_name" : "Smith"} }        --> Peter Smith
    { "update": { "_id": "2"} }    
    { "doc" : {"new_author_first_name" : "Smith", "new_author_last_name" : "Williams"} }        --> Smith Williams
    { "update": { "_id": "3"} }
    { "doc" : {"new_author_first_name" : "Jack", "new_author_last_name" : "Ma"} }            --> Jack Ma
    { "update": { "_id": "4"} }
    { "doc" : {"new_author_first_name" : "Robbin", "new_author_last_name" : "Li"} }            --> Robbin Li
    { "update": { "_id": "5"} }
    { "doc" : {"new_author_first_name" : "Tonny", "new_author_last_name" : "Peter Smith"} }        --> Tonny Peter Smith
    
    GET /forum/article/_search
    {
      "query": {
        "match": {
          "new_author_full_name":       "Peter Smith"
        }
      }
    }
    
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"author_first_name" : "Peter", "author_last_name" : "Smith"} }
    { "update": { "_id": "2"} }
    { "doc" : {"author_first_name" : "Smith", "author_last_name" : "Williams"} }
    { "update": { "_id": "3"} }
    { "doc" : {"author_first_name" : "Jack", "author_last_name" : "Ma"} }
    { "update": { "_id": "4"} }
    { "doc" : {"author_first_name" : "Robbin", "author_last_name" : "Li"} }
    { "update": { "_id": "5"} }
    { "doc" : {"author_first_name" : "Tonny", "author_last_name" : "Peter Smith"} }
    
    GET /forum/article/_search
    {
      "query": {
        "multi_match": {
          "query":       "Peter Smith",
          "type":        "most_fields",
          "fields":      [ "author_first_name", "author_last_name" ]
        }
      }
    }
    POST /forum/_mapping/article
    {
      "properties": {
          "sub_title": { 
              "type":     "string",
              "analyzer": "english",
              "fields": {
                  "std":   { 
                      "type":     "string",
                      "analyzer": "standard"
                  }
              }
          }
      }
    }
    
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"sub_title" : "learning more courses"} }
    { "update": { "_id": "2"} }
    { "doc" : {"sub_title" : "learned a lot of course"} }
    { "update": { "_id": "3"} }
    { "doc" : {"sub_title" : "we have a lot of fun"} }
    { "update": { "_id": "4"} }
    { "doc" : {"sub_title" : "both of them are good"} }
    { "update": { "_id": "5"} }
    { "doc" : {"sub_title" : "haha, hello world"} }
    
    GET /forum/article/_search
    {
      "query": {
        "match": {
          "sub_title": "learning courses"
        }
      }
    }
    GET /forum/article/_search
    {
       "query": {
            "match": {
                "sub_title": "learning courses"
            }
        }
    }
    
    
    GET /forum/article/_search
    {
        "query": {
            "dis_max": {
                "queries": [
                    { "match": { "title": "java beginner" }},
                    { "match": { "body":  "java beginner" }}
                ]
            }
        }
    }
    GET /forum/article/_search
    {
        "query": {
            "dis_max": {
                "queries": [
                    { "match": { "title": "java beginner" }},
                    { "match": { "body":  "java beginner" }}
                ],
                "tie_breaker": 0.3
            }
        }
    }
    
    
    
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"content" : "i like to write best elasticsearch article"} }
    { "update": { "_id": "2"} }
    { "doc" : {"content" : "i think java is the best programming language"} }
    { "update": { "_id": "3"} }
    { "doc" : {"content" : "i am only an elasticsearch beginner"} }
    { "update": { "_id": "4"} }
    { "doc" : {"content" : "elasticsearch and hadoop are all very good solution, i am a beginner"} }
    { "update": { "_id": "5"} }
    { "doc" : {"content" : "spark is best big data solution based on scala ,an programming language similar to java"} }
    GET /forum/article/_search
    {
        "query": {
            "bool": {
                "should": [
                    { "match": { "title": "java solution" }},
                    { "match": { "content":  "java solution" }}
                ]
            }
        }
    }
    GET /forum/article/_search
    {
        "query": {
            "dis_max": {
                "queries": [
                    { "match": { "title": "java solution" }},
                    { "match": { "content":  "java solution" }}
                ]
            }
        }
    }
    
    GET /forum/article/_search 
    {
      "query": {
        "bool": {
          "must": [
            {
              "match": {
                "title": "blog"
              }
            }
          ],
          "should": [
            {
              "match": {
                "title": {
                  "query": "java"
                }
              }
            },
            {
              "match": {
                "title": {
                  "query": "hadoop"
                }
              }
            },
            {
              "match": {
                "title": {
                  "query": "elasticsearch"
                }
              }
            },
            {
              "match": {
                "title": {
                  "query": "spark",
                  "boost": 5
                }
              }
            }
          ]
        }
      }
    }
    
    
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"title" : "this is java and elasticsearch blog"} }
    { "update": { "_id": "2"} }
    { "doc" : {"title" : "this is java blog"} }
    { "update": { "_id": "3"} }
    { "doc" : {"title" : "this is elasticsearch blog"} }
    { "update": { "_id": "4"} }
    { "doc" : {"title" : "this is java, elasticsearch, hadoop blog"} }
    { "update": { "_id": "5"} }
    { "doc" : {"title" : "this is spark blog"} }
    
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"title" : "this is java and elasticsearch blog"} }
    { "update": { "_id": "2"} }
    { "doc" : {"title" : "this is java blog"} }
    { "update": { "_id": "3"} }
    { "doc" : {"title" : "this is elasticsearch blog"} }
    { "update": { "_id": "4"} }
    { "doc" : {"title" : "this is java, elasticsearch, hadoop blog"} }
    { "update": { "_id": "5"} }
    { "doc" : {"title" : "this is spark blog"} }
    GET /forum/article/_search
    {
        "query": {
            "match": {
                "title": {
            "query": "java elasticsearch",
            "operator": "and"
               }
            }
        }
    }
    GET /forum/article/_search
    {
        "query": {
            "match": {
                "title": {
            "query": "java elasticsearch",
            "operator": "and"
               }
            }
        }
    }
    GET /forum/article/_search
    {
      "query": {
        "bool": {
          "must":     { "match": { "title": "java" }},
          "must_not": { "match": { "title": "spark"  }},
          "should": [
                      { "match": { "title": "hadoop" }},
                      { "match": { "title": "elasticsearch"   }}
          ]
        }
      }
    }
    GET /forum/article/_search
    {
      "query": {
        "bool": {
          "should": [
            { "match": { "title": "java" }},
            { "match": { "title": "elasticsearch"   }},
            { "match": { "title": "hadoop"   }},
        { "match": { "title": "spark"   }}
          ],
          "minimum_should_match": 3 
        }
      }
    }
    GET /books/_search
    {
      "size": 0,
      "aggs": {
        "grades_stats": {
          "stats": {
            "field": "price"
          }
        }
      }
    }
    
    
    
    GET /_search
    {
      "query": {
        "bool": {
          "should": [
            { "match": { "address": "mill" } },
            { "match": { "address": "lane" } }
          ]
        }
      }
    }
    
    
    PUT my_index/my_type/1
    {
      "full_text":   "Quick Foxes!", 
      "exact_value": "Quick Foxes!"  
    }
    
    
    GET my_index/my_type/_search
    {
      "query": {
        "term": {
          "exact_value": "Quick Foxes!" 
        }
      }
    }
    
    GET my_index/my_type/_search
    {
      "query": {
        "term": {
          "full_text": "Quick Foxes!" 
        }
      }
    }
    GET my_index/my_type/_search
    {
      "query": {
        "term": {
          "full_text": "foxes" 
        }
      }
    }
    
    GET my_index/my_type/_search
    {
      "query": {
        "match": {
          "full_text": "Quick Foxes!" 
        }
      }
    }
    
    
    
    
    
    POST /termtest/termtype/1
    {
      "content":"Name"
    }
    
    POST /termtest/termtype/2
    {
      "content":"name city"
    }
    
    GET /termtest/_search
    {
      "query":
      {
        "match_all": {}
      }
    }
    
    POST /termtest/_search
    {
      "query":{
        "term":{
          "content":"name"
        }
      }
    }
    
    POST /termtest/_search
    {
      "query":{
        "match":{
          "content":"Name"
        }
      }
    }
    
    
    
    
    
    
    
    
    
    PUT my_index/my_type/2
    {
     "zuMaker":
        {"type":"keyword","index":"false"}
    
    }
    
    PUT my_index/my_type/3
    {
    "zuName":
           {"type":"text","index":"true","boost":"5","analyzer":"ik_max_word","search_analyzer":"ik_max_word"}
    
    
    }
    
    
    
    
    
    
    PUT my_index/my_type/2
    {
     "zuMaker":
        {"type":"keyword","index":"false"}
    
    }
    
    PUT my_index/my_type/3
    {
    "zuName":
           {"type":"text","index":"true","boost":"5","analyzer":"ik_max_word","search_analyzer":"ik_max_word"}
    
    
    }
    
    
    GET my_index/my_type/_search
    
     { "query": { "term": { "zuName": "墙体钢结构" } } }
    
    GET my_index/my_type/_search
    { "query": { "term": { "zuMakert": "张三李四" } } }
    
    GET my_index/my_type/_search
    
    
    PUT my_index/my_type/2
    {
     "zuMaker":
      {
      "type": "keyword",
      "index": "false",
      "content":"张三李四"
    }
    
    }
    
    PUT my_index/my_type/3
    {
      "zuName": {
        "type": "text",
        "index": "true",
        "boost": "5",
        "analyzer": "ik_max_word",
        "search_analyzer": "ik_max_word",
         "content":"墙体钢结构"
      }
    }
    GET my_index/_search
    
            { "query": { "term": { "zuMakert": "张三李四" } } }
    
    
    //设置mapping
    POST /productindex/product/_mapping?pretty
    {
        "product": {
                "properties": {
                    "title": {
                        "type": "string",
                        "store": "yes"
                    },
                    "description": {
                        "type": "string",
                        "index": "not_analyzed"
                    },
                    "price": {
                        "type": "double"
                    },
                    "onSale": {
                        "type": "boolean"
                    },
                    "type": {
                        "type": "integer"
                    },
                    "createDate": {
                        "type": "date"
                    }
                }
            }
      }
    
    //新增mapping
    POST /productindex/product/_mapping?pretty
    {
         "product": {
                    "properties": {
                         "amount":{
                            "type":"integer"
                       }
                    }
                }
        }
    
    POST /productindex/product/_mapping?pretty
    {
         "product": {
                    "properties": {
                     "onSale":{
                        "type":"string" 
                   }
                }
            }
    }
    
    
    //设置mapping之后,插入数据
    POST /productindex/product/1
    {
        "title" : "John",
        "description" :  "Smith",
        "price" :        25,
        "onSale" :  ""  ,
        "type": 1,
        "createDate" : "2017-08-26"
    }
    
    
    //精确查找
    
    GET /test_index2/_search
    {
      "query": {
        "match_phrase": {
          "title":"Java程序性能优化"
        }
      }
    }
    
    
    //如果我们希望两个字段进行匹配,其中一个字段有这个文档就满足的话,使用multi_match
    
    GET /test_index2/_search
    {
      "query": {
        "multi_match": {
           "query" : "Java程序性能优化",
          "fields" : ["title", "language"]
        }
      }
    }
    
    
    //boolean 查询
    
    GET /test_index2/_search
    {
      "query": {
        "bool": {
          "must": {
            "term": {
              "title": "java"
            }
          },
          "must_not": {
            "term": {
              "language": "javascript"
            }
          }
        }
      }
    }
    
    
    //and  or 查询
    
    
    GET /test_index2/_search
    {
        "query": {
            "match": {
                "title": {      
                   "query":    "Java Python",
                    "operator": "or"   --and
                }
            }
        }
    }
    
    
    
    
    //range 过滤
    
    GET /_search
    {
      "query": {
        "range": {
          "age": {
            "gte": 25,
            "lt": 30
          }
        }
      }
    }
    
    #The filtered query has been deprecated and removed in ES 5.0. You should now use the bool/must/filter query instead.
    
    {
        "query": {
            "bool": {
                "must": {
                    "multi_match": {
                        "operator": "and",
                        "fields": [
                            "author",
                            "title",
                            "publisher",
                            "year"
                        ],
                        "query": "George Orwell"
                    }
                },
                "filter": {
                    "terms": {
                        "year": [
                            1980,
                            1981
                        ]
                    }
                }
            }
        }
    }
    PUT /artists/
    {
      "settings": {
        "analysis": {
          "analyzer": {
            "user_name_analyzer": {
              "tokenizer": "whitespace",
              "filter": "pinyin_first_letter_and_full_pinyin_filter"
            }
          },
          "filter": {
            "pinyin_first_letter_and_full_pinyin_filter": {
              "type": "pinyin",
              "keep_first_letter": true,
              "keep_full_pinyin": false,
              "keep_none_chinese": true,
              "keep_original": false,
              "limit_first_letter_length": 16,
              "lowercase": true,
              "trim_whitespace": true,
              "keep_none_chinese_in_first_letter": true
            }
          }
        }
      }
    }
    
    GET /artists/_analyze
    {
      "text": ["刘德华 张学友 郭富城 黎明 王传付  四大天王"],
      "analyzer": "user_name_analyzer"
    }
    
    
    #查询指定条件的数据
    #select  * from order o where o.price=20
     GET /my_store/_search
    {
      "query": {
        "bool": {
          "must": {
            "match_all": {
             
            }
          },
          "filter": {
            "term": {
              "price" : 20
            }
          }
        }
      }
    }
    
    
    
    
    PUT /website 
    {
      "mappings": {
        "article": {
          "properties": {
            "title": {
              "type": "text",
              "fields": {
                "raw": {
                  "type": "string",
                  "index": "not_analyzed"
                }
              },
              "fielddata": true
            },
            "content": {
              "type": "text"
            },
            "post_date": {
              "type": "date"
            },
            "author_id": {
              "type": "long"
            }
          }
        }
      }
    }
    
    PUT /website/article/1
    {
      "title": "first article",
      "content": "this is my second article",
      "post_date": "2017-01-01",
      "author_id": 110
    }
    
    {
      "took": 2,
      "timed_out": false,
      "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
      },
      "hits": {
        "total": 3,
        "max_score": 1,
        "hits": [
          {
            "_index": "website",
            "_type": "article",
            "_id": "2",
            "_score": 1,
            "_source": {
              "title": "first article",
              "content": "this is my first article",
              "post_date": "2017-02-01",
              "author_id": 110
            }
          },
          {
            "_index": "website",
            "_type": "article",
            "_id": "1",
            "_score": 1,
            "_source": {
              "title": "second article",
              "content": "this is my second article",
              "post_date": "2017-01-01",
              "author_id": 110
            }
          },
          {
            "_index": "website",
            "_type": "article",
            "_id": "3",
            "_score": 1,
            "_source": {
              "title": "third article",
              "content": "this is my third article",
              "post_date": "2017-03-01",
              "author_id": 110
            }
          }
        ]
      }
    }
    
    GET /website/article/_search
    {
      "query": {
        "match_all": {}
      },
      "sort": [
        {
          "title.raw": {
            "order": "desc"
          }
        }
      ]
    }
    
    
    
    
    GET /_search
    {
        "query" : {
            "bool" : {
                "filter" : {
                    "term" : {
                        "author_id" : 1
                    }
                }
            }
        }
    }
    
    当然,也可以是constant_score
    
    GET /_search
    {
        "query" : {
            "constant_score" : {
                "filter" : {
                    "term" : {
                        "author_id" : 1
                    }
                }
            }
        }
    }
    
    2、定制排序规则
    
    GET /company/employee/_search 
    {
      "query": {
        "constant_score": {
          "filter": {
            "range": {
              "age": {
                "gte": 30
              }
            }
          }
        }
      },
      "sort": [
        {
          "join_date": {
            "order": "asc"
          }
        }
      ]
    }
    
    
    
    
    
    
    GET /website/article/_search
    {
      "query": {
        "bool": {
          "must": [
            {
              "match": {
                "title": "elasticsearch"
              }
            }
          ],
          "should": [
            {
              "match": {
                "content": "elasticsearch"
              }
            }
          ],
          "must_not": [
            {
              "match": {
                "author_id": 111
              }
            }
          ]
        }
      }
    }
    
    GET /test_index/_search
    {
        "query": {
                "bool": {
                    "must": { "match":   { "name": "tom" }},
                    "should": [
                        { "match":       { "hired": true }},
                        { "bool": {
                            "must":      { "match": { "personality": "good" }},
                            "must_not":  { "match": { "rude": true }}
                        }}
                    ],
                    "minimum_should_match": 1
                }
        }
    }
    
    
    
    
    
    1、match all
    
    GET /_search
    {
        "query": {
            "match_all": {}
        }
    }
    
    2、match
    
    GET /_search
    {
        "query": { "match": { "title": "my elasticsearch article" }}
    }
    
    3、multi match
    
    GET /test_index/test_type/_search
    {
      "query": {
        "multi_match": {
          "query": "test",
          "fields": ["test_field", "test_field1"]
        }
      }
    }
    
    4、range query
    
    GET /company/employee/_search 
    {
      "query": {
        "range": {
          "age": {
            "gte": 30
          }
        }
      }
    }
    
    5、term query
    
    GET /test_index/test_type/_search 
    {
      "query": {
        "term": {
          "test_field": "test hello"
        }
      }
    }
    
    6、terms query
    
    GET /_search
    {
        "query": { "terms": { "tag": [ "search", "full_text", "nosql" ] }}
    }
    PUT /company/employee/2
    {
      "address": {
        "country": "china",
        "province": "jiangsu",
        "city": "nanjing"
      },
      "name": "tom",
      "age": 30,
      "join_date": "2016-01-01"
    }
    
    PUT /company/employee/3
    {
      "address": {
        "country": "china",
        "province": "shanxi",
        "city": "xian"
      },
      "name": "marry",
      "age": 35,
      "join_date": "2015-01-01"
    }
    
    GET /company/employee/_search
    {
      "query": {
        "bool": {
          "must": [
            {
              "match": {
                "join_date": "2016-01-01"
              }
            }
          ],
          "filter": {
            "range": {
              "age": {
                "gte": 30
              }
            }
          }
        }
      }
    }
    
    
    2、修改mapping
    
    只能创建index时手动建立mapping,或者新增field mapping,但是不能update field mapping
    
    PUT /website
    {
      "mappings": {
        "article": {
          "properties": {
            "author_id": {
              "type": "long"
            },
            "title": {
              "type": "text",
              "analyzer": "english"
            },
            "content": {
              "type": "text"
            },
            "post_date": {
              "type": "date"
            },
            "publisher_id": {
              "type": "text",
              "index": "not_analyzed"
            }
          }
        }
      }
    }
    
    PUT /website
    {
      "mappings": {
        "article": {
          "properties": {
            "author_id": {
              "type": "text"
            }
          }
        }
      }
    }
    PUT /website/_mapping/article
    {
      "properties" : {
        "new_field" : {
          "type" :    "string",
          "index":    "not_analyzed"
        }
      }
    }
    
    GET /website/_mapping
    3、测试mapping
    
    GET /website/_analyze
    {
      "field": "content",
      "text": "my-dogs" 
    }
    
    GET website/_analyze
    {
      "field": "new_field",
      "text": "my dogs"
    }
    
    {
      "error": {
        "root_cause": [
          {
            "type": "remote_transport_exception",
            "reason": "[4onsTYV][127.0.0.1:9300][indices:admin/analyze[s]]"
          }
        ],
        "type": "illegal_argument_exception",
        "reason": "Can't process field [new_field], Analysis requests are only supported on tokenized fields"
      },
      "status": 400
    }
    
    PUT /website/article/1
    {
      "post_date": "2017-01-01",
      "title": "my first article",
      "content": "this is my first article in this website",
      "author_id": 11400
    }
    
    PUT /website/article/2
    {
      "post_date": "2017-01-02",
      "title": "my second article",
      "content": "this is my second article in this website",
      "author_id": 11400
    }
    
    PUT /website/article/3
    {
      "post_date": "2017-01-03",
      "title": "my third article",
      "content": "this is my third article in this website",
      "author_id": 11400
    }
    
    尝试各种搜索
    
    GET /website/_mapping/article
    
    {
      "website": {
        "mappings": {
          "article": {
            "properties": {
              "author_id": {
                "type": "long"
              },
              "content": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "post_date": {
                "type": "date"
              },
              "title": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              }
            }
          }
        }
      }
    }
    
    GET /_search
    
    {
      "took": 6,
      "timed_out": false,
      "_shards": {
        "total": 6,
        "successful": 6,
        "failed": 0
      },
      "hits": {
        "total": 10,
        "max_score": 1,
        "hits": [
          {
            "_index": ".kibana",
            "_type": "config",
            "_id": "5.2.0",
            "_score": 1,
            "_source": {
              "buildNum": 14695
            }
          }
        ]
      }
    }
    #bulk语法
    
    POST /_bulk
    { "delete": { "_index": "test_index", "_type": "test_type", "_id": "3" }} 
    { "create": { "_index": "test_index", "_type": "test_type", "_id": "12" }}
    { "test_field":    "test12" }
    { "index":  { "_index": "test_index", "_type": "test_type", "_id": "2" }}
    { "test_field":    "replaced test2" }
    { "update": { "_index": "test_index", "_type": "test_type", "_id": "1", "_retry_on_conflict" : 3} }
    { "doc" : {"test_field2" : "bulk test1"} }
    
    POST /test_index/_bulk
    { "delete": { "_type": "test_type", "_id": "3" }} 
    { "create": { "_type": "test_type", "_id": "12" }}
    { "test_field":    "test12" }
    { "index":  { "_type": "test_type" }}
    { "test_field":    "auto-generate id test" }
    { "index":  { "_type": "test_type", "_id": "2" }}
    { "test_field":    "replaced test2" }
    { "update": { "_type": "test_type", "_id": "1", "_retry_on_conflict" : 3} }
    { "doc" : {"test_field2" : "bulk test1"} }
    
    POST /test_index/test_type/_bulk
    { "delete": { "_id": "3" }} 
    { "create": { "_id": "12" }}
    { "test_field":    "test12" }
    { "index":  { }}
    { "test_field":    "auto-generate id test" }
    { "index":  { "_id": "2" }}
    { "test_field":    "replaced test2" }
    { "update": { "_id": "1", "_retry_on_conflict" : 3} }
    { "doc" : {"test_field2" : "bulk test1"} }
    
    
    GET /_mget
    {
       "docs" : [
          {
             "_index" : "test_index",
             "_type" :  "test_type",
             "_id" :    1
          },
          {
             "_index" : "test_index",
             "_type" :  "test_type",
             "_id" :    2
          }
       ]
    }
    
    {
      "docs": [
        {
          "_index": "test_index",
          "_type": "test_type",
          "_id": "1",
          "_version": 2,
          "found": true,
          "_source": {
            "test_field1": "test field1",
            "test_field2": "test field2"
          }
        },
        {
          "_index": "test_index",
          "_type": "test_type",
          "_id": "2",
          "_version": 1,
          "found": true,
          "_source": {
            "test_content": "my test"
          }
        }
      ]
    }
    
    (3)如果查询的document是一个index下的不同type种的话
    
    GET /test_index/_mget
    {
       "docs" : [
          {
             "_type" :  "test_type",
             "_id" :    1
          },
          {
             "_type" :  "test_type",
             "_id" :    2
          }
       ]
    }
    
    (4)如果查询的数据都在同一个index下的同一个type下,最简单了
    
    GET /test_index/test_type/_mget
    {
       "ids": [1, 2]
    }
    
    
    PUT /test_index/test_type/11
    {
      "num": 0,
      "tags": []
    }
    POST /test_index/test_type/11/_update
    {
       "script" : "ctx._source.num+=1"
    }
    
    {
      "_index": "test_index",
      "_type": "test_type",
      "_id": "11",
      "_version": 2,
      "found": true,
      "_source": {
        "num": 1,
        "tags": []
      }
    }
    
    
    POST /test_index/test_type/11/_update
    {
      "script": {
        "lang": "groovy", 
        "file": "test-add-tags",
        "params": {
          "new_tag": "tag1"
        }
      }
    }
    POST /test_index/test_type/11/_update
    {
      "doc": {
        "num": 1
      }
    }
    GET /ecommerce/product/_search
    {
      "aggs": {
        "group_by_tags": {
          "terms": { "field": "tags" }
        }
      }
    }
    
    GET /car/_search
    
    GET /car/_search
    {
      "aggs": {
        "group_by_color": {
          "terms": { "field": "color" }
        }
      }
    }
    PUT /ecommerce/_mapping/product
    {
      "properties": {
        "tags": {
          "type": "text",
          "fielddata": true
        }
      }
    }
    GET /ecommerce/product/_search
    {
      "size": 0,
      "aggs": {
        "all_tags": {
          "terms": { "field": "tags" }
        }
      }
    }
    GET /ecommerce/product/_search
    {
      "size": 0,
      "query": {
        "match": {
          "name": "yagao"
        }
      },
      "aggs": {
        "all_tags": {
          "terms": {
            "field": "tags"
          }
        }
      }
    }
    GET /ecommerce/product/_search
    {
        "size": 0,
        "aggs" : {
            "group_by_tags" : {
                "terms" : { "field" : "tags" },
                "aggs" : {
                    "avg_price" : {
                        "avg" : { "field" : "price" }
                    }
                }
            }
        }
    }
    
    
    GET /ecommerce/product/_search
    {
        "size": 0,
        "aggs" : {
            "all_tags" : {
                "terms" : { "field" : "tags", "order": { "avg_price": "desc" } },
                "aggs" : {
                    "avg_price" : {
                        "avg" : { "field" : "price" }
                    }
                }
            }
        }
    }
    
    GET /ecommerce/product/_search
    {
      "size": 0,
      "aggs": {
        "group_by_price": {
          "range": {
            "field": "price",
            "ranges": [
              {
                "from": 0,
                "to": 20
              },
              {
                "from": 20,
                "to": 40
              },
              {
                "from": 40,
                "to": 50
              }
            ]
          },
          "aggs": {
            "group_by_tags": {
              "terms": {
                "field": "tags"
              },
              "aggs": {
                "average_price": {
                  "avg": {
                    "field": "price"
                  }
                }
              }
            }
          }
        }
      }
    }
    GET /ecommerce/product/_search
    {
      "query": { "match_all": {} }
    }
    
    
    
    GET /ecommerce/product/_search
    {
        "query" : {
            "match" : {
                "name" : "yagao"
            }
        },
        "sort": [
            { "price": "desc" }
        ]
    }
    GET /ecommerce/product/_search
    {
      "query": { "match_all": {} },
      "from": 1,
      "size": 1
    }
    GET /ecommerce/product/_search
    {
      "query": { "match_all": {} },
      "_source": ["name", "price"]
    }
    
    GET /ecommerce/product/_search
    {
        "query" : {
            "bool" : {
                "must" : {
                    "match" : {
                        "name" : "yagao" 
                    }
                },
                "filter" : {
                    "range" : {
                        "price" : { "gt" : 25 } 
                    }
                }
            }
        }
    }
    
    GET /ecommerce/product/_search
    {
        "query" : {
            "match" : {
                "producer" : "yagao producer"
            }
        }
    }
    GET /ecommerce/product/_search
    {
        "query" : {
            "match_phrase" : {
                "producer" : "yagao producer"
            }
        }
    }
    GET /ecommerce/product/_search
    {
        "query" : {
            "match" : {
                "producer" : "producer"
            }
        },
        "highlight": {
            "fields" : {
                "producer" : {}
            }
        }
    }
    POST /forum/article/_bulk
    { "index": { "_id": 1 }}
    { "articleID" : "XHDK-A-1293-#fJ3", "userID" : 1, "hidden": false, "postDate": "2017-01-01" }
    { "index": { "_id": 2 }}
    { "articleID" : "KDKE-B-9947-#kL5", "userID" : 1, "hidden": false, "postDate": "2017-01-02" }
    { "index": { "_id": 3 }}
    { "articleID" : "JODL-X-1937-#pV7", "userID" : 2, "hidden": false, "postDate": "2017-01-01" }
    { "index": { "_id": 4 }}
    { "articleID" : "QQPX-R-3956-#aD8", "userID" : 2, "hidden": true, "postDate": "2017-01-02" }
    
    
    
    
    
    GET /forum/_mapping/article
    
    {
      "forum": {
        "mappings": {
          "article": {
            "properties": {
              "articleID": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "hidden": {
                "type": "boolean"
              },
              "postDate": {
                "type": "date"
              },
              "userID": {
                "type": "long"
              }
            }
          }
        }
      }
    }
    GET /forum/article/_search
    {
        "query" : {
            "constant_score" : { 
                "filter" : {
                    "term" : { 
                        "userID" : 1
                    }
                }
            }
        }
    }
    
    GET /forum/article/_search
    {
        "query" : {
            "constant_score" : { 
                "filter" : {
                    "term" : { 
                        "hidden" : false
                    }
                }
            }
        }
    }
    GET /forum/article/_search
    {
        "query" : {
            "constant_score" : { 
                "filter" : {
                    "term" : { 
                        "postDate" : "2017-01-01"
                    }
                }
            }
        }
    }
    
    GET /forum/article/_search
    {
        "query" : {
            "constant_score" : { 
                "filter" : {
                    "term" : { 
                        "articleID" : "XHDK-A-1293-#fJ3"
                    }
                }
            }
        }
    }
    GET /forum/_analyze
    {
      "field": "articleID",
      "text": "XHDK-A-1293-#fJ3"
    }
    
    DELETE /forum
    
    PUT /forum
    {
      "mappings": {
        "article": {
          "properties": {
            "articleID": {
              "type": "keyword"
            }
          }
        }
      }
    }
    
    POST /forum/article/_bulk
    { "index": { "_id": 1 }}
    { "articleID" : "XHDK-A-1293-#fJ3", "userID" : 1, "hidden": false, "postDate": "2017-01-01" }
    { "index": { "_id": 2 }}
    { "articleID" : "KDKE-B-9947-#kL5", "userID" : 1, "hidden": false, "postDate": "2017-01-02" }
    { "index": { "_id": 3 }}
    { "articleID" : "JODL-X-1937-#pV7", "userID" : 2, "hidden": false, "postDate": "2017-01-01" }
    { "index": { "_id": 4 }}
    { "articleID" : "QQPX-R-3956-#aD8", "userID" : 2, "hidden": true, "postDate": "2017-01-02" }
    
    
    GET /forum/article/_search
    {
        "query" : {
            "constant_score" : { 
                "filter" : {
                    "term" : { 
                        "articleID" : "XHDK-A-1293-#fJ3"
                    }
                }
            }
        }
    }
    PUT test_index/test_type/1
    {
      "test_field":"test1"
    }
    
    
    GET  test_index/test_type/_search
    
    PUT test_index/test_type/1?version=1
    {
      "test_field":"test3"
    }
    
    GET website/_search
    GET website/_mapping/blogs
    
    
    GET /website/_analyze
    {
      "field": "content",
      "text": "my-dogs" 
    }
    
    GET /_analyze
    {
      "analyzer": "ik_max_word",
      "text": "中华人民共和国"
    }
    
    GET /_analyze
    {
      "analyzer": "standard",
      "text": "中华人民共和国"
    }
    
    GET /_analyze
    {
      "analyzer": "index_ansj",
      "text": "中华人民共和国"
    }
    
    
    
    GET /jd_item/_mapping
    
    GET /jd_item/jd_item/_search
    {
      "query": {
        "match": {
          "title": "飞利浦"
        }
      }
    }
    
    
    
    
    
    
    
    GET /jd_item/jd_item/_search
    {
      "from":0,
      "size":20,
      "query": {
        "bool": {
          "must": [
            {
             "query_string": {
              "default_field": "title",
              "query": "飞利浦"
             }
            },
            {
              "query_string": {
                "default_field": "id",
                "query": "1106502"
              }
            }
          ]
        }
      }
    }
    
    GET /jd_item/jd_item/_search
    {
      "query": {
        "match": {
          "title": "飞利"
        }
      }
    }
    GET /tvs/sales/_search
    {
       "size" : 0,
       "aggs":{
          "price":{
             "histogram":{ 
                "field": "price",
                "interval": 2000
             },
             "aggs":{
                "revenue": {
                   "sum": { 
                     "field" : "price"
                   }
                 }
             }
          }
       }
    }
    
    GET /tvs/sales/_search 
    {
      "size": 0,
      "query": {
        "term": {
          "brand": {
            "value": "长虹"
          }
        }
      },
      "aggs": {
        "recent_150d": {
          "filter": {
            "range": {
              "sold_date": {
                "gte": "now-150d"
              }
            }
          },
          "aggs": {
            "recent_150d_avg_price": {
              "avg": {
                "field": "price"
              }
            }
          }
        },
        "recent_140d": {
          "filter": {
            "range": {
              "sold_date": {
                "gte": "now-140d"
              }
            }
          },
          "aggs": {
            "recent_140d_avg_price": {
              "avg": {
                "field": "price"
              }
            }
          }
        },
        "recent_130d": {
          "filter": {
            "range": {
              "sold_date": {
                "gte": "now-130d"
              }
            }
          },
          "aggs": {
            "recent_130d_avg_price": {
              "avg": {
                "field": "price"
              }
            }
          }
        }
      }
    }
    
    GET /spnews/news/_search
    {
      "query": {
        "multi_match": {
          "query": "足球",
          "fields": [
            "content^1.0",
            "title^1.0"
          ],
          "type": "best_fields",
          "operator": "OR",
          "slop": 0,
          "prefix_length": 0,
          "max_expansions": 50,
          "lenient": false,
          "zero_terms_query": "NONE",
          "boost": 1
        }
      },
      "highlight": {
        "pre_tags": [
          "<font style='color:red'>"
        ],
        "post_tags": [
          "</font>"
        ],
        "fields": {
          "title": {},
          "content": {}
        }
      }
    }
    GET /spnews/news/_search
    {
      "from": 0,
      "size": 28,
      "query": {
        "bool": {
          "must": [
            {
              "bool": {
                "should": [
                  {
                    "match": {
                      "productCommonName": {
                        "query": "感冒药",
                        "type": "boolean",
                        "operator": "AND",
                        "boost": 4
                      }
                    }
                  },
                  {
                    "match": {
                      "productName": {
                        "query": "感冒药",
                        "type": "boolean",
                        "operator": "AND",
                        "boost": 1
                      }
                    }
                  },
                  {
                    "match": {
                      "productChnNo": {
                        "query": "感冒药",
                        "type": "boolean",
                        "operator": "AND",
                        "boost": 1
                      }
                    }
                  },
                  {
                    "match": {
                      "proCatalogName": {
                        "query": "感冒药",
                        "type": "boolean",
                        "operator": "AND",
                        "boost": 4
                      }
                    }
                  },
                  {
                    "match": {
                      "productBrandName": {
                        "query": "感冒药",
                        "type": "boolean",
                        "operator": "AND",
                        "boost": 4
                      }
                    }
                  },
                  {
                    "match": {
                      "productBrandName1": {
                        "query": "感冒药",
                        "type": "boolean",
                        "operator": "AND",
                        "boost": 4
                      }
                    }
                  },
                  {
                    "match": {
                      "productKeyword": {
                        "query": "感冒药",
                        "type": "boolean",
                        "operator": "AND",
                        "boost": 4
                      }
                    }
                  }
                ]
              }
            },
            {
              "bool": {
                "should": [
                  {
                    "range": {
                      "saleScore": {
                        "from": 50,
                        "to": null,
                        "include_lower": false,
                        "include_upper": true,
                        "boost": 200
                      }
                    }
                  },
                  {
                    "range": {
                      "saleScore": {
                        "from": null,
                        "to": 50,
                        "include_lower": true,
                        "include_upper": false,
                        "boost": 1
                      }
                    }
                  }
                ]
              }
            }
          ]
        }
      },
      "post_filter": {
        "bool": {
          "must_not": {
            "term": {
              "ecPrice": -1
            }
          }
        }
      },
      "sort": [
        {
          "stock": {
            "order": "desc"
          }
        },
        {
          "_score": {
            "order": "desc"
          }
        }
      ],
      "highlight": {
        "pre_tags": [
          "<em>"
        ],
        "post_tags": [
          "</em>"
        ],
        "fields": {
          "productName": {
            "fragment_size": 70
          }
        }
      }
    }
    GET /test_index/test_type/_search 
    {
        "query": {
            "match": {
                "search_field": "test"
            }
        },
        "aggs": {
            "group_by_agg_field": {
                "terms": {
                    "field": "agg_field"
                }
            }
        }
    }
    
    
    
    
    
    
    
    
    GET /website/users/_search 
    {
      "query": {
        "term": {
          "name.keyword": {
            "value": "小鱼儿"
          }
        }
      }
    }
    
    
    GET /forum/_mapping/article
    
    {
      "forum": {
        "mappings": {
          "article": {
            "properties": {
              "articleID": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "hidden": {
                "type": "boolean"
              },
              "postDate": {
                "type": "date"
              },
              "userID": {
                "type": "long"
              }
            }
          }
        }
      }
    }
    
    GET /forum/article/_search
    
    
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"tag" : ["java", "hadoop"]} }
    { "update": { "_id": "2"} }
    { "doc" : {"tag" : ["java"]} }
    { "update": { "_id": "3"} }
    { "doc" : {"tag" : ["hadoop"]} }
    { "update": { "_id": "4"} }
    { "doc" : {"tag" : ["java", "elasticsearch"]} }
    
    GET /forum/article/_search
    {
        "query" : {
            "constant_score" : {
                "filter" : {
                    "terms" : { 
                        "tag" : ["java"]
                    }
                }
            }
        }
    }
    
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"tag_cnt" : 2} }
    { "update": { "_id": "2"} }
    { "doc" : {"tag_cnt" : 1} }
    { "update": { "_id": "3"} }
    { "doc" : {"tag_cnt" : 1} }
    { "update": { "_id": "4"} }
    { "doc" : {"tag_cnt" : 2} }
    
    
    
    POST /forum/article/_bulk
    { "index": { "_id": 1 }}
    { "articleID" : "XHDK-A-1293-#fJ3", "userID" : 1, "hidden": false, "postDate": "2017-01-01" }
    { "index": { "_id": 2 }}
    { "articleID" : "KDKE-B-9947-#kL5", "userID" : 1, "hidden": false, "postDate": "2017-01-02" }
    { "index": { "_id": 3 }}
    { "articleID" : "JODL-X-1937-#pV7", "userID" : 2, "hidden": false, "postDate": "2017-01-01" }
    { "index": { "_id": 4 }}
    { "articleID" : "QQPX-R-3956-#aD8", "userID" : 2, "hidden": true, "postDate": "2017-01-02" }
    GET /forum/article/_search
    
    GET /forum/article/_search
    {
      "query": {
        "constant_score": {
          "filter": {
            "bool": {
              "must": [
                {
                  "term": {
                    "tag_cnt": 1
                  }
                },
                {
                  "terms": {
                    "tag": ["java"]
                  }
                }
              ]
            }
          }
        }
      }
    }
    
    GET /forum/article/_search
    {
        "query" : {
            "constant_score" : { 
                "filter" : {
                    "term" : { 
                        "hidden" : false
                    }
                }
            }
        }
    }
    
    GET /forum/article/_search
    {
        "query" : {
            "constant_score" : { 
                "filter" : {
                    "term" : { 
                        "postDate" : "2017-01-01"
                    }
                }
            }
        }
    }
    
    GET /forum/article/_search
    {
        "query" : {
            "constant_score" : { 
                "filter" : {
                    "term" : { 
                        "articleID" : "XHDK-A-1293-#fJ3"
                    }
                }
            }
        }
    }
    
    
    GET /forum/article/_search
    {
        "query" : {
            "constant_score" : { 
                "filter" : {
                    "term" : { 
                        "articleID.keyword" : "XHDK-A-1293-#fJ3"
                    }
                }
            }
        }
    }
    POST /forum/article/_bulk
    { "index": { "_id": 1 }}
    { "articleID" : "XHDK-A-1293-#fJ3", "userID" : 1, "hidden": false, "postDate": "2017-01-01" }
    { "index": { "_id": 2 }}
    { "articleID" : "KDKE-B-9947-#kL5", "userID" : 1, "hidden": false, "postDate": "2017-01-02" }
    { "index": { "_id": 3 }}
    { "articleID" : "JODL-X-1937-#pV7", "userID" : 2, "hidden": false, "postDate": "2017-01-01" }
    { "index": { "_id": 4 }}
    { "articleID" : "QQPX-R-3956-#aD8", "userID" : 2, "hidden": true, "postDate": "2017-01-02" }
    GET /forum/article/_search
    {
        "query" : {
            "constant_score" : { 
                "filter" : {
                    "term" : { 
                        "articleID" : "XHDK-A-1293-#fJ3"
                    }
                }
            }
        }
    }
    
    GET /forum/article/_search
    {
        "query": {
            "dis_max": {
                "queries": [
                    { "match": { "title": "java beginner" }},
                    { "match": { "content":  "java beginner" }}
                ]
            }
        }
    }
    GET /forum/article/_search
    {
        "query": {
            "dis_max": {
                "queries": [
                    { "match": { "title": "java beginner" }},
                    { "match": { "content":  "java beginner" }}
                ],
                "tie_breaker": 0.3
            }
        }
    }
    GET /my_index/my_type/_search 
    {
      "query": {
        "match_phrase_prefix": {
          "title": "hello d"
        }
      }
    }
    
    GET /my_index/my_type/_search 
    {
      "query": {
        "fuzzy": {
          "text": {
            "value": "surprize",
            "fuzziness": 2
          }
        }
      }
    }
    
    
    GET /forum/article/_search
    {
      "query": {
        "multi_match": {
          "query":       "Peter Smith",
          "type":        "most_fields",
          "fields":      [ "author_first_name", "author_last_name" ]
        }
      }
    }
    
    
    
    GET /forum/article/_search 
    {
      "query": {
        "bool": {
          "should": [
            {
              "match": {
                "content": "java"
              }
            },
            {
              "match": {
                "content": "spark"
              }
            },
            {
              "bool": {
                "should": [
                  {
                    "match": {
                      "content": "solution"
                    }
                  },
                  {
                    "match": {
                      "content": "beginner"
                    }
                  }
                ]
              }
            }
          ]
        }
      }
    }
    GET /forum/article/_search 
    {
      "query": {
        "bool": {
          "must": [
            {
              "match": {
                "content": "java"
              }
            }
          ],
          "must_not": [
            {
              "match": {
                "content": "spark"
              }
            }
          ]
        }
      }
    }
    
    
    GET /forum/article/_search 
    {
      "query": {
        "boosting": {
          "positive": {
            "match": {
              "content": "java"
            }
          },
          "negative": {
            "match": {
              "content": "spark"
            }
          },
          "negative_boost": 0.2
        }
      }
    }
    
    GET /forum/article/_search 
    {
      "query": {
        "bool": {
          "should": [
            {
              "constant_score": {
                "query": {
                  "match": {
                    "title": "java"
                  }
                }
              }
            },
            {
              "constant_score": {
                "query": {
                  "match": {
                    "title": "spark"
                  }
                }
              }
            }
          ]
        }
      }
    }
    {
      "took": 2,
      "timed_out": false,
      "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
      },
      "hits": {
        "total": 3,
        "max_score": 0.6931472,
        "hits": [
          {
            "_index": "forum",
            "_type": "article",
            "_id": "2",
            "_score": 0.6931472,
            "_source": {
              "articleID": "KDKE-B-9947-#kL5",
              "userID": 1,
              "hidden": false,
              "postDate": "2017-01-02",
              "tag": [
                "java"
              ],
              "tag_cnt": 1,
              "view_cnt": 50,
              "title": "this is java blog",
              "content": "i think java is the best programming language",
              "sub_title": "learned a lot of course",
              "author_first_name": "Smith",
              "author_last_name": "Williams"
            }
          },
          {
            "_index": "forum",
            "_type": "article",
            "_id": "1",
            "_score": 0.5753642,
            "_source": {
              "articleID": "XHDK-A-1293-#fJ3",
              "userID": 1,
              "hidden": false,
              "postDate": "2017-01-01",
              "tag": [
                "java",
                "hadoop"
              ],
              "tag_cnt": 2,
              "view_cnt": 30,
              "title": "this is java and elasticsearch blog",
              "content": "i like to write best elasticsearch article",
              "sub_title": "learning more courses",
              "author_first_name": "Peter",
              "author_last_name": "Smith"
            }
          },
          {
            "_index": "forum",
            "_type": "article",
            "_id": "5",
            "_score": 0.51623213,
            "_source": {
              "articleID": "DHJK-B-1395-#Ky5",
              "userID": 3,
              "hidden": false,
              "postDate": "2017-03-01",
              "tag": [
                "elasticsearch"
              ],
              "tag_cnt": 1,
              "view_cnt": 10,
              "title": "this is spark blog",
              "content": "spark is best big data solution based on scala ,an programming language similar to java",
              "sub_title": "haha, hello world",
              "author_first_name": "Tonny",
              "author_last_name": "Peter Smith"
            }
          }
        ]
      }
    }
    
    PUT /tvs
    {
        "mappings": {
            "sales": {
                "properties": {
                    "price": {
                        "type": "long"
                    },
                    "color": {
                        "type": "keyword"
                    },
                    "brand": {
                        "type": "keyword"
                    },
                    "sold_date": {
                        "type": "date"
                    }
                }
            }
        }
    }
    
    POST /tvs/sales/_bulk
    { "index": {}}
    { "price" : 1000, "color" : "红色", "brand" : "长虹", "sold_date" : "2016-10-28" }
    { "index": {}}
    { "price" : 2000, "color" : "红色", "brand" : "长虹", "sold_date" : "2016-11-05" }
    { "index": {}}
    { "price" : 3000, "color" : "绿色", "brand" : "小米", "sold_date" : "2016-05-18" }
    { "index": {}}
    { "price" : 1500, "color" : "蓝色", "brand" : "TCL", "sold_date" : "2016-07-02" }
    { "index": {}}
    { "price" : 1200, "color" : "绿色", "brand" : "TCL", "sold_date" : "2016-08-19" }
    { "index": {}}
    { "price" : 2000, "color" : "红色", "brand" : "长虹", "sold_date" : "2016-11-05" }
    { "index": {}}
    { "price" : 8000, "color" : "红色", "brand" : "三星", "sold_date" : "2017-01-01" }
    { "index": {}}
    { "price" : 2500, "color" : "蓝色", "brand" : "小米", "sold_date" : "2017-02-12" }
    
    
    GET /tvs/sales/_search
    {
        "size" : 0,
        "aggs" : { 
            "popular_colors" : { 
                "terms" : { 
                  "field" : "color"
                }
            }
        }
    }
    
    GET /tvs/sales/_search 
    {
      "size": 0,
      "query": {
        "constant_score": {
          "filter": {
            "range": {
              "price": {
                "gte": 1200
              }
            }
          }
        }
      },
      "aggs": {
        "avg_price": {
          "avg": {
            "field": "price"
          }
        }
      }
    }
    GET /tvs/sales/_search
    {
      "size" : 0,
      "aggs" : {
          "months" : {
            "date_histogram": {
              "field": "sold_date",
              "interval": "month"
            },
            "aggs": {
              "distinct_colors" : {
                  "cardinality" : {
                    "field" : "brand"
                  }
              }
            }
          }
      }
    }
    
    PUT /blog_website
    {
      "mappings": {
        "blogs": {
          "properties": {
            "title": {
              "type": "text",
              "analyzer": "ik_max_word"
            },
            "content": {
              "type": "text",
              "analyzer": "ik_max_word"
            }
          }
        }
      }
    }
    
    PUT /blog_website/blogs/1
    {
      "title": "我的第一篇博客",
      "content": "大家好,这是我写的第一篇博客,特别喜欢这个博客网站!!!"
    }
    
    
    GET /blog_website/blogs/_search 
    {
      "query": {
        "match": {
          "title": "博客"
        }
      },
      "highlight": {
        "fields": {
          "title": {}
        }
      }
    }
    
    
    
    GET /blog_website/blogs/_search 
    {
      "query": {
        "bool": {
          "should": [
            {
              "match": {
                "title": "博客"
              }
            },
            {
              "match": {
                "content": "博客"
              }
            }
          ]
        }
      },
      "highlight": {
        "fields": {
          "title": {},
          "content": {}
        }
      }
    }
    
    
    PUT /news_website
    {
      "mappings": {
        "news" : {
          "properties" : {
            "title" : {
              "type": "text",
              "analyzer": "ik_max_word",
              "fields": {
                "suggest" : {
                  "type" : "completion",
                  "analyzer": "ik_max_word"
                }
              }
            },
            "content": {
              "type": "text",
              "analyzer": "ik_max_word"
            }
          }
        }
      }
    }
    
    PUT /news_website_pinyin
    {
      "mappings": {
        "news_pinyin" : {
          "properties" : {
            "title" : {
              "type": "text",
              "analyzer": "pinyin_analyzer",
              "fields": {
                "suggest" : {
                  "type" : "completion",
                  "analyzer": "pinyin_analyzer"
                }
              }
            },
            "content": {
              "type": "text",
              "analyzer": "pinyin_analyzer"
            }
          }
        }
      }
    }
    
    
    
    PUT /medcl1/
    {
        "index" : {
            "analysis" : {
                "analyzer" : {
                    "ngram_pinyin_analyzer" : {
                        "tokenizer" : "keyword",
                        "filter" : ["full_pinyin_with_space","word_delimiter","shingle","remove_whitespace"]
                    }, "my_pinyin_analyzer" : {
                        "tokenizer" : "keyword",
                        "filter" : ["full_pinyin_no_space"]
                    }
                },
                "filter" :{
                    "full_pinyin_no_space" : {
                        "type" : "pinyin",
                        "first_letter" : "none",
                        "padding_char" : ""
                },"full_pinyin_with_space" : {
                        "type" : "pinyin",
                        "first_letter" : "none",
                        "padding_char" : " "
                },
                 "my_edge_ngram_tokenizer" : {
                            "type" : "edgeNGram",
                            "min_gram" : "2",
                            "max_gram" : "5",
                            "token_chars": [ "letter", "digit" ]
                        },
                        "remove_whitespace": {
                        "type":       "pattern_replace",
                        "pattern": "\s+",
                        "replacement":""
                    }
            }
            }
        }
    }
    
    POST medcl1/type/_mapping
    {
      "properties": {
        "name1":{
          "type": "multi_field",
          "fields": {
            "pinyin":{
              "type": "string", 
              "analyzer": "ngram_pinyin_analyzer"
            }, "full_pinyin":{
              "type": "string", 
              "analyzer": "my_pinyin_analyzer"
            },
            "first_letter":{
              "type": "string", 
              "analyzer": "pinyin_first_letter"
            },
            "name1":{
              "type": "string", 
              "analyzer": "ik_max_word"
            }
          }
        }
      }
    }
    
    
    GET medcl1/_mapping
    
    
    POST medcl1/type3/
    {
      "name1":"刘德华"
    }
    POST medcl1/type3/
    {
      "name1":"刘斌"
    }
    POST medcl1/type3/
    {
      "name1":"张三"
    }
    POST medcl1/type3/
    {
      "name1":"李四"
    }
    POST medcl1/type3/
    {
      "name1":"刘德志"
    }
    
    POST medcl1/_search?size=50
    {
      "query": {
        "query_string": {
          "fields": ["name1","name1.full_pinyin","name1.pinyin","name1.first_letter"],
          "query": "刘德华",
          "default_operator": "AND"
        }
      }
    }
    
    PUT /search_text
    {
      "settings": {
        "refresh_interval": "5s",
        "number_of_shards": 1,
        "number_of_replicas": 1,
        "analysis": {
          "filter": {
            "edge_ngram_filter": {
              "type": "edge_ngram",
              "min_gram": 1,
              "max_gram": 50
            },
            "pinyin_full_filter": {
              "type": "pinyin",
              "keep_first_letter": false,
              "keep_separate_first_letter": false,
              "keep_full_pinyin": true,
              "keep_original": false,
              "limit_first_letter_length": 50,
              "lowercase": true
            },
            "pinyin_simple_filter": {
              "type": "pinyin",
              "keep_first_letter": true,
              "keep_separate_first_letter": false,
              "keep_full_pinyin": false,
              "keep_original": false,
              "limit_first_letter_length": 50,
              "lowercase": true
            }
          },
          "analyzer": {
            "pinyiSimpleIndexAnalyzer": {
              "type": "custom",
              "tokenizer": "keyword",
              "filter": [
                "pinyin_simple_filter",
                "edge_ngram_filter",
                "lowercase"
              ]
            },
            "pinyiFullIndexAnalyzer": {
              "type": "custom",
              "tokenizer": "keyword",
              "filter": [
                "pinyin_full_filter",
                "lowercase"
              ]
            }
          }
        }
      }
    }
    
    
    PUT /search_text/_mapping/list
    {
      "properties": {
        "name": {
          "type": "keyword",
          "fields": {
            "fpy": {
              "type": "text",
              "index": true,
              "analyzer": "pinyiFullIndexAnalyzer"
            },
            "spy": {
              "type": "text",
              "index": true,
              "analyzer": "pinyiSimpleIndexAnalyzer"
            }
          }
        }
      }
    }
    
     
    PUT /search_text/list/4
    {
      "name":"刘德华"
    }
    
    
    
    
    PUT /search_text/list/2
    {
      "name":"天命"
    }
    PUT /search_text/list/3
    {
      "name":"你好明天"
    }
    POST /search_text/list/_search
    {
      "query":{
          "match":{
              "name.fpy":{
                  "query":"liudehua",
                  "operator": "and"
              }
          }
      }
    }
    
    GET  /news_website/news/_mapping
    
    PUT /news_website/news/1
    {
      "title": "大话西游电影dhxy",
      "content": "大话西游的电影时隔20年即将在2017年4月重映"
    }
    PUT /news_website/news/2
    {
      "title": "大话西游小说dhxy",
      "content": "某知名网络小说作家已经完成了大话西游同名小说的出版"
    }
    PUT /news_website/news/3
    {
      "title": "大话西游手游dhxy",
      "content": "网易游戏近日出品了大话西游经典IP的手游,正在火爆内测中"
    }
    
    GET /news_website/news/_search
    {
      "suggest": {
        "my-suggest" : {
          "prefix" : "dhxy",
          "completion" : {
            "field" : "title.suggest"
          }
        }
      }
    }
    GET /news_website/news/_search 
    {
      "query": {
        "match": {
          "content": "大话西游电影"
        }
      }
    }
    
    
    PUT /my_index
    {
      "mappings": {
        "my_type": {
          "properties": {
            "text": {
                "type": "text",
                "term_vector": "with_positions_offsets_payloads",
                "store" : true,
                "analyzer" : "fulltext_analyzer"
             },
             "fullname": {
                "type": "text",
                "analyzer" : "fulltext_analyzer"
            }
          }
        }
      },
      "settings" : {
        "index" : {
          "number_of_shards" : 1,
          "number_of_replicas" : 0
        },
        "analysis": {
          "analyzer": {
            "fulltext_analyzer": {
              "type": "custom",
              "tokenizer": "whitespace",
              "filter": [
                "lowercase",
                "type_as_payload"
              ]
            }
          }
        }
      }
    }
    
    
    PUT /my_index/my_type/1
    {
      "fullname" : "Leo Li",
      "text" : "hello test test test "
    }
    
    PUT /my_index/my_type/2
    {
      "fullname" : "Leo Li",
      "text" : "other hello test ..."
    }
    
    GET /my_index/my_type/1/_termvectors
    {
      "fields" : ["text"],
      "offsets" : true,
      "payloads" : true,
      "positions" : true,
      "term_statistics" : true,
      "field_statistics" : true
    }
    
    {
      "_index": "my_index",
      "_type": "my_type",
      "_id": "1",
      "_version": 1,
      "found": true,
      "took": 10,
      "term_vectors": {
        "text": {
          "field_statistics": {
            "sum_doc_freq": 6,
            "doc_count": 2,
            "sum_ttf": 8
          },
          "terms": {
            "hello": {
              "doc_freq": 2,
              "ttf": 2,
              "term_freq": 1,
              "tokens": [
                {
                  "position": 0,
                  "start_offset": 0,
                  "end_offset": 5,
                  "payload": "d29yZA=="
                }
              ]
            },
            "test": {
              "doc_freq": 2,
              "ttf": 4,
              "term_freq": 3,
              "tokens": [
                {
                  "position": 1,
                  "start_offset": 6,
                  "end_offset": 10,
                  "payload": "d29yZA=="
                },
                {
                  "position": 2,
                  "start_offset": 11,
                  "end_offset": 15,
                  "payload": "d29yZA=="
                },
                {
                  "position": 3,
                  "start_offset": 16,
                  "end_offset": 20,
                  "payload": "d29yZA=="
                }
              ]
            }
          }
        }
      }
    }
    GET /my_index/my_type/1/_termvectors
    {
      "fields" : ["fullname"],
      "offsets" : true,
      "positions" : true,
      "term_statistics" : true,
      "field_statistics" : true
    }GET /my_index/my_type/_termvectors
    {
      "doc" : {
        "fullname" : "Leo Li",
        "text" : "hello test test test"
      },
      "fields" : ["text"],
      "offsets" : true,
      "payloads" : true,
      "positions" : true,
      "term_statistics" : true,
      "field_statistics" : true
    }
    GET /company/rd_center/_search 
    {
      "size": 0,
      "aggs": {
        "group_by_country": {
          "terms": {
            "field": "country.keyword"
          },
          "aggs": {
            "group_by_child_employee": {
              "children": {
                "type": "employee"
              },
              "aggs": {
                "group_by_hobby": {
                  "terms": {
                    "field": "hobby.keyword"
                  }
                }
              }
            }
          }
        }
      }
    }
    
    
    
    
    GET /movies/_search
    {
      "from": 0, 
      "size": 10000, 
      "query": {
        "match_all": {}
      }
    }
    
    GET /forum/_search
    
    GET /forum/_mapping/article
    
    
    GET /forum/_search
    {
      "query": {
        "constant_score": {
          "filter": {
            "term": {
              "userID": "1"
            }
          }
        }
      }
    }
    
    
    GET /forum/_search
    {
      "query": {
        "bool": {
          "must_not": [
            {
              "term": {
                "postDate": {
                  "value": "2017-01-02"
                }
              }
            }
          ],
          "should": [
            {
              "term": {
                "postDate": "2017-01-01"
              }
            },
            {
              "term": {
                "articleID": "XHDK-A-1293-#fJ3"
              }
            }
          ]
        }
      }
    }
    
     GET /forum/_search
    {
      "query": {
        "bool": {
          "should": [
            {
              "term": {
                "postDate":"2017-01-01"
                
              }
            },{
              "term": {
                "articleID":"XHDK-A-1293-#fJ3"
              }
            }
          ]
        }
      }
    }
     GET /forum/_search
    {
      "query": {
        "bool": {
          "should": [
            {
              "term": {
                 "postDate":"2017-01-01"
              }
            },{
              "term": {
                "articleID":"XHDK-A-1293-#fJ3"
              }
            }
          ],
          "must_not": [
            {
              "term": {
                "postDate":"2017-01-02"
              }
            }
          ]
        }
      }
    }
    GET /forum/_search
    {
      "query": {
        "constant_score": {
          "filter": {
            "bool": {
              "should": [
                {
                  "term": {
                "articleID": "XHDK-A-1293-#fJ3"
                  }
                }
              ],
              "bool": {
                "must": [
                  {
                    "term": {
                    "articleID": "JODL-X-1937-#pV7"
                    }
                  }
                ]
              }
            }
          }
        }
      }
    }
    
    GET /forum/article/_search
    {
      "query": {
        "constant_score": {
          "filter": {
            "bool": {
              "should": [
                {
                  "term": {
                    "articleID": "XHDK-A-1293-#fJ3"
                  }
                },
                {
                  "bool": {
                    "must": [
                      {
                        "term": {
                          "articleID": "JODL-X-1937-#pV7"
                        }
                      },
                      {
                        "term": {
                          "postDate": "2017-01-01"
                        }
                      }
                    ]
                  }
                }
              ]
            }
          }
        }
      }
    }
    
    #搜索帖子ID为XHDK-A-1293-#fJ3,或者是帖子ID为JODL-X-1937-#pV7而且发帖日期为2017-01-01的帖子
    
    
    GET /forum/article/_search
    {
      "query": {
        "constant_score": {
          "filter": {
            "bool": {
              "should": [
                {
                  "term": {
                    "articleID": "XHDK-A-1293-#fJ3"
                  }
                },
                {
                  "bool": {
                    "must": [
                      {
                        "term": {
                          "postDate": "2017-01-01"
                        }
                      },
                      {
                        "term":{
                          "articleID": "JODL-X-1937-#pV7"
                        }
                      }
                    ]
                  }
                }
              ]
            }
          }
        }
      }
    }
    GET /forum/article/_search
    {
      "query": {
        "bool": {
          "must": [
           {
              "term": {
                 "postDate": "2017-01-01"
              }
            }
          ],
          "should": [
            {
              "term": {
                 "articleID": "XHDK-A-1293-#fJ3"
              }
            }, {
              "term": {"articleID": "JODL-X-1937-#pV7"
              }
            }
          ]
        }
      }
    }
    GET /forum/article/_search 
    {
      "query": {
        "constant_score": {
          "filter": {
            "terms": {
              "articleID": [
                "KDKE-B-9947-#kL5",
                "QQPX-R-3956-#aD8"
              ]
            }
          }
        }
      }
    }
    
    GET /forum/article/_search 
    {
      "query": {
        "constant_score": {
          "filter": {
            "terms": {
              "articleID": [
               "KDKE-B-9947-#kL5",
                "QQPX-R-3956-#aD8"
              ]
            }
          }
        }
      }
    }
    GET /forum/article/_search
    {
      "query": {
        "constant_score": {
          "filter": {
            "terms": {
              "tag" : ["java"]
            }
          }
        }
      }
    }
    
    
    
    
    
    
    
    GET /forum/article/_search
    {
      "query": {
        "constant_score": {
          "filter": {
            "bool": {
              "must": [
                {
                  "term": {
                    "tag_cnt": 1
                  }
                },
                {
                  "terms": {
                    "tag": ["java"]
                  }
                }
              ]
            }
          }
        }
      }
    }
    
    
    GET /forum/article/_search
    {
      "query": {
        "constant_score": {
         "filter": {
           "bool": {
             "must":[
               {
                 "term":{
                    "tag_cnt": 1
                 }
               },{
                 "terms":{
                      "tag": ["java"]
                 }
               }
               ]
           }
         }
        }
      }
    }
    
    GET /forum/article/_search
    {
      "query": {
        "constant_score": {
          "filter": {
            "range": {
              "view_cnt": {
                "gte": 30,
                "lte": 60
              }
            }
          }
          
        }
      }
    }
    #最近一个月的帖子 
    GET /forum/article/_search 
    {
      "query": {
        "constant_score": {
          "filter": {
            "range": {
              "postDate": {
              "gt": "2017-03-10||-30d"
              }
            }
          }
        }
      }
    }
    
    GET /forum/article/_search 
    {
      "query": {
        "constant_score": {
          "filter": {
            "range": {
              "postDate": {
                "gte": "now-30d"
              }
            }
          }
        }
      }
    }
    GET /forum/article/_mapping
    GET /forum/article/_search
    {
      "query": {
        "match": {
          "title": "java elasticsearch"
        }
      }
    }
    
    
    
    GET /forum/article/_search
    {
      "query": {
        "match": {
          "title": {
            "query": "java elasticsearch",
            "operator": "and"
          }
        }
      }
    }
    GET /forum/article/_search
    {
      "query": {
        "match": {
          "title":{
            "query": "java elasticsearch spark hadoop",
            "minimum_should_match": "75%"
          }
        }
      }
    }
    GET /forum/article/_search
    {
      "query": {
      "bool": {
        "must": [
          {
            "match": {
              "title": "java" 
            }
          }
        ],"must_not": [
          {
            "match": {
             "title": "spark"  
            }
          }
        ],
        "should": [
          {
            "match": {
              "title": "hadoop"
            }
          },{
            "match": {
              "title": "elasticsearch"
            }
          }
        ]
      }
      }
    }
    GET /forum/article/_search
    {
      "query": {
        "bool": {
          "must": {
            "match": {
              "title": "java"
            }
          },
          "must_not": {
            "match": {
              "title": "spark"
            }
          },
          "should": [
            {
              "match": {
                "title": "hadoop"
              }
            },
            {
              "match": {
                "title": "elasticsearch"
              }
            }
          ]
        }
      }
    }
    GET /forum/article/_search
    {
      "query": {
        "bool": {
          "should": [
            {
              "match": {
               "title": "java"
              }
            },
            {
              "match": {
                "title": "elasticsearch"  
              }
            },
            {
              "match": {
                "title": "spark"  
              }
            },
            {
              "match": {
                "title": "hadoop"  
              }
            }
            
          ],
          "minimum_should_match": 3
        }
      }
    }
    
    GET /forum/article/_search
    {
      "query": {
        "match": {
          "title": {
           "query": "",
           "operator": "and"
          }
        }
      }
    }
    
    
    
    GET /forum/article/_search 
    {
      "query": {
        "bool": {
          "must": [
            {
              "match": {
                "title": "blog"
              }
            }
          ],
          "should": [
            {
              "match": {
                "title": {
                  "query": "java"
                }
              }
            },
            {
              "match": {
                "title": {
                  "query": "hadoop"
                }
              }
            },
            {
              "match": {
                "title": {
                  "query": "elasticsearch"
                }
              }
            },
            {
              "match": {
                "title": {
                  "query": "spark",
                  "boost": 5
                }
              }
            }
          ]
        }
      }
    }
    
    
    
    
    
    
    GET /forum/article/_search 
    {
      "query": {
        "bool": {
          "must": [
            {
              "match": {
                "title": "blog"
              }
            }
          ],
          "should": [
            {
              "match": {
                "title": {
                  "query": "java"
                }
              }
            },
            {
              "match": {
                "title": {
                  "query": "hadoop"
                }
              }
            },
            {
              "match": {
                "title": {
                  "query": "elasticsearch"
                }
              }
            },
            {
              "match": {
                "title": {
                  "query": "spark",
                  "boost": 5
                }
              }
            }
          ]
        }
      }
    }
    
    GET /forum/article/_search
    {
        "query": {
            "bool": {
                "should": [
                    { "match": { "title": "java solution" }},
                    { "match": { "content":  "java solution" }}
                ]
            }
        }
    }
    
    GET /forum/article/_search
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"content" : "i like to write best elasticsearch article"} }
    { "update": { "_id": "2"} }
    { "doc" : {"content" : "i think java is the best programming language"} }
    { "update": { "_id": "3"} }
    { "doc" : {"content" : "i am only an elasticsearch beginner"} }
    { "update": { "_id": "4"} }
    { "doc" : {"content" : "elasticsearch and hadoop are all very good solution, i am a beginner"} }
    { "update": { "_id": "5"} }
    { "doc" : {"content" : "spark is best big data solution based on scala ,an programming language similar to java"} }
    GET /forum/article/_search
    {
      "query":{
        "bool": {
          "should": [
            {
              "match": {
               "content":  "java solution"
              }
            },{
              "match": {
               "title": "java solution"
              }
            }
          ]
        }
      }
    }
    GET /forum/article/_search
    
    GET /forum/article/_search
    {
      "query": {
        "bool": {
          "should": [
            {
              "match": {
                "content":  "java solution"
              }
            },
            {
              "match": {
              "title": "java solution"
              }
            }
          ]
        }
      }
    }
    
    GET /forum/article/_search
    {
      "query": {
        "dis_max": {
          "queries": [
            {
              "match": {
               "title": "java solution"
              }
            },{
              "match": {
               "content":  "java solution"
              }
            }
            ]
        }
      }
    }
    
    GET /forum/article/_search
    {
        "query": {
            "dis_max": {
                "queries": [
                    { "match": { "title": "java beginner" }},
                    { "match": { "content":  "java beginner" }}
                ],
                "tie_breaker": 0.3
                
            }
        }
    }
    
    GET /forum/article/_search
    {
      "query": {
        "multi_match": {
          "query": "java solution",
          "fields": [ "title^2", "content" ],
                  "tie_breaker":          0.3,
            "minimum_should_match": "50%" 
    
        }
      }
    }
    
    GET /forum/article/_search
    {
      "query": {
        "match": {
          "sub_title": "learning courses"
        }
      }
    }
    
    GET /forum/article/_search
    {
      "query": {
        "match": {
          "sub_title": "Tlearning courses"
        }
      }
    }
    GET /forum/article/_mapping
    
    
    POST /forum/_mapping/article
    {
      "properties": {
          "sub_title": { 
              "type":     "string",
              "analyzer": "english",
              "fields": {
                  "std":   { 
                      "type":     "string",
                      "analyzer": "standard"
                  }
              }
          }
      }
    }
    
    
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"sub_title" : "learning more courses"} }
    { "update": { "_id": "2"} }
    { "doc" : {"sub_title" : "learned a lot of course"} }
    { "update": { "_id": "3"} }
    { "doc" : {"sub_title" : "we have a lot of fun"} }
    { "update": { "_id": "4"} }
    { "doc" : {"sub_title" : "both of them are good"} }
    { "update": { "_id": "5"} }
    { "doc" : {"sub_title" : "haha, hello world"} }
    
    GET /forum/article/_search
    
    GET /forum/article/_search
    {
      "query": {
        "match": {
          "sub_title": "learning courses"
        }
      }
    }
    
    POST /forum/_mapping/article
    {
      "properties": {
          "sub_title": { 
              "type":     "string",
              "analyzer": "english",
              "fields": {
                  "std":   { 
                      "type":     "string",
                      "analyzer": "standard"
                  }
              }
          }
      }
    }
    post /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"sub_title" : "learning more courses"} }
    { "update": { "_id": "2"} }
    { "doc" : {"sub_title" : "learned a lot of course"} }
    { "update": { "_id": "3"} }
    { "doc" : {"sub_title" : "we have a lot of fun"} }
    { "update": { "_id": "4"} }
    { "doc" : {"sub_title" : "both of them are good"} }
    { "update": { "_id": "5"} }
    { "doc" : {"sub_title" : "haha, hello world"} }
    
    
    GET /forum/article/_search
    {
      "query": {
        "match": {
          "sub_title": "learning courses"
        }
      }
    }
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"title" : "this is java and elasticsearch blog"} }
    { "update": { "_id": "2"} }
    { "doc" : {"title" : "this is java blog"} }
    { "update": { "_id": "3"} }
    { "doc" : {"title" : "this is elasticsearch blog"} }
    { "update": { "_id": "4"} }
    { "doc" : {"title" : "this is java, elasticsearch, hadoop blog"} }
    { "update": { "_id": "5"} }
    { "doc" : {"title" : "this is spark blog"} }
    
    
    get /forum/article/_search
    
    
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"title" : "this is java and elasticsearch blog"} }
    { "update": { "_id": "2"} }
    { "doc" : {"title" : "this is java blog"} }
    { "update": { "_id": "3"} }
    { "doc" : {"title" : "this is elasticsearch blog"} }
    { "update": { "_id": "4"} }
    { "doc" : {"title" : "this is java, elasticsearch, hadoop blog"} }
    { "update": { "_id": "5"} }
    { "doc" : {"title" : "this is spark blog"} }
    
    
    
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"tag" : ["java", "hadoop"]} }
    { "update": { "_id": "2"} }
    { "doc" : {"tag" : ["java"]} }
    { "update": { "_id": "3"} }
    { "doc" : {"tag" : ["hadoop"]} }
    { "update": { "_id": "4"} }
    { "doc" : {"tag" : ["java", "elasticsearch"]} }
    
    
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"title" : "this is java and elasticsearch blog"} }
    { "update": { "_id": "2"} }
    { "doc" : {"title" : "this is java blog"} }
    { "update": { "_id": "3"} }
    { "doc" : {"title" : "this is elasticsearch blog"} }
    { "update": { "_id": "4"} }
    { "doc" : {"title" : "this is java, elasticsearch, hadoop blog"} }
    { "update": { "_id": "5"} }
    { "doc" : {"title" : "this is spark blog"} }
    
    
    POST /forum/_mapping/article
    {
      "properties": {
          "sub_title": { 
              "type":     "string",
              "analyzer": "english",
              "fields": {
                  "std":   { 
                      "type":     "string",
                      "analyzer": "standard"
                  }
              }
          }
      }
    }
    
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"sub_title" : "learning more courses"} }
    { "update": { "_id": "2"} }
    { "doc" : {"sub_title" : "learned a lot of course"} }
    { "update": { "_id": "3"} }
    { "doc" : {"sub_title" : "we have a lot of fun"} }
    { "update": { "_id": "4"} }
    { "doc" : {"sub_title" : "both of them are good"} }
    { "update": { "_id": "5"} }
    { "doc" : {"sub_title" : "haha, hello world"} }
    
    
    
    GET /forum/article/_search
    {
      "query": {
        "match": {
          "sub_title": "learning courses"
        }
      }
    }
    
    
    GET /forum/article/_search
    {
       "query": {
            "match": {
                "sub_title": "learning courses"
            }
        }
    }
    
    
    GET /forum/article/_search
    {
       "query": {
            "multi_match": {
                "query":  "learning courses",
                "type":   "most_fields", 
                "fields": [ "sub_title", "sub_title.std" ]
            }
        }
    }
    
    
    
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"author_first_name" : "Peter", "author_last_name" : "Smith"} }
    { "update": { "_id": "2"} }
    { "doc" : {"author_first_name" : "Smith", "author_last_name" : "Williams"} }
    { "update": { "_id": "3"} }
    { "doc" : {"author_first_name" : "Jack", "author_last_name" : "Ma"} }
    { "update": { "_id": "4"} }
    { "doc" : {"author_first_name" : "Robbin", "author_last_name" : "Li"} }
    { "update": { "_id": "5"} }
    { "doc" : {"author_first_name" : "Tonny", "author_last_name" : "Peter Smith"} }
    
    
    GET /forum/article/_search
    {
      "query": {
        "multi_match": {
          "query": "Peter Smith",
          "type": "most_fields", 
          "fields": ["author_first_name","author_last_name"]
        }
      }
    }
    
    PUT /forum/_mapping/article
    {
      "properties": {
          "new_author_first_name": {
              "type":     "string",
              "copy_to":  "new_author_full_name" 
          },
          "new_author_last_name": {
              "type":     "string",
              "copy_to":  "new_author_full_name" 
          },
          "new_author_full_name": {
              "type":     "string"
          }
      }
    }
    
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"new_author_first_name" : "Peter", "new_author_last_name" : "Smith"} }    
    { "update": { "_id": "2"} }    
    { "doc" : {"new_author_first_name" : "Smith", "new_author_last_name" : "Williams"} }    
    { "update": { "_id": "3"} }
    { "doc" : {"new_author_first_name" : "Jack", "new_author_last_name" : "Ma"} }        
    { "update": { "_id": "4"} }
    { "doc" : {"new_author_first_name" : "Robbin", "new_author_last_name" : "Li"} }        
    { "update": { "_id": "5"} }
    { "doc" : {"new_author_first_name" : "Tonny", "new_author_last_name" : "Peter Smith"} }    
    
    
    GET /forum/article/_search
    {
      "query": {
        "match": {
          "new_author_full_name":       "Peter Smith"
        }
      }
    }
    GET /forum/article/_search
    {
      "from": 0,
      "size": 20, 
      "query": {
        "match": {
          "content": "java "
        }
      }
    }
    GET /forum/article/_search
    {
      "query": {
        "match_phrase": {
          "content": "java  spark"
        }
      }
    }
    
    POST /forum/article/3/_update
    {
      "doc": {
        "content": "spark is best big data solution based on scala ,an programming language similar to java spark"
      }
    }
    
    GET /_analyze
    {
      "text": "hello world, java spark",
      "analyzer": "standard"
    }
    
    GET /forum/article/_search
    {
        "query": {
            "match_phrase": {
                "content": "java spark"
            }
        }
    }
    
    GET /forum/article/_search
    {
      "query": {
        "match_all": {}
      }
    }
    
    GET /forum/article/_search
    {
      "query": {
        "match_phrase": {
          "content": {
            "query": "java best",
            "slop": 10
          }
        }
      }
    }
    GET /forum/article/_search
    {
      "query": {
        "bool": {
          "must": [
            {
              "match": {
                "content": "java spark"
              }
            }
          ],
          "should": [
            {
              "match_phrase": {
                "content":{
                  "query": "java spark",
                  "slop":50
                }
              }
            }
          ]
        }
      }
    }
    GET /forum/article/_search 
    {
      "query": {
        "match": {
          "content": "java spark"
        }
      },
      "rescore": {
        "window_size": 50,
        "query": {
          "rescore_query": {
            "match_phrase": {
              "content": {
                "query": "java spark",
                "slop": 50
              }
            }
          }
        }
      }
    }
    
    
    GET /forum/article/_search
    {
      "query": {
        "bool": {
          "should": [
            {
              "match": {
                "title": {
                  "query": "java spark",
                  "boost":2
                }
              }
            },
            {
              "match":{
                
                  "content": "java spark"
                
              }
            }
          ]
        }
      }
    }
    
    
    GET /forum/article/_search
    {
      "query": {
        "bool": {
          "should": [
            {
              "match": {
                "title": {
                  "query": "java spark",
                  "boost": 2
                }
              }
            },
            {
              "match": {
                "content": "java spark"
              }
            }
          ]
        }
      }
    }
    
    
    
    
    
    
    
    
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"content" : "i like to write best elasticsearch article"} }
    { "update": { "_id": "2"} }
    { "doc" : {"content" : "i think java is the best programming language"} }
    { "update": { "_id": "3"} }
    { "doc" : {"content" : "i am only an elasticsearch beginner"} }
    { "update": { "_id": "4"} }
    { "doc" : {"content" : "elasticsearch and hadoop are all very good solution, i am a beginner"} }
    { "update": { "_id": "5"} }
    { "doc" : {"content" : "spark is best big data solution based on scala ,an programming language similar to java"} }
    
    POST /forum/article/_bulk
    { "update": { "_id": "1"} }
    { "doc" : {"follower_num" : 5} }
    { "update": { "_id": "2"} }
    { "doc" : {"follower_num" : 10} }
    { "update": { "_id": "3"} }
    { "doc" : {"follower_num" : 25} }
    { "update": { "_id": "4"} }
    { "doc" : {"follower_num" : 3} }
    { "update": { "_id": "5"} }
    { "doc" : {"follower_num" : 60} }
    
    
    GET /forum/article/_search
    {
      "query": {
        "function_score": {
          "query": {
            "multi_match": {
              "query": "java spark",
              "fields": ["tile", "content"]
            }
          },
          "field_value_factor": {
            "field": "follower_num",
            "modifier": "log1p",
            "factor": 0.5
          },
          "boost_mode": "sum",
          "max_boost": 2
        }
      }
    }
    POST /my_index/my_type/_bulk
    { "index": { "_id": 1 }}
    { "text": "Surprise me!"}
    { "index": { "_id": 2 }}
    { "text": "That was surprising."}
    { "index": { "_id": 3 }}
    { "text": "I wasn't surprised."}
    
    GET /my_index/my_type/_search 
    {
      "query": {
        "fuzzy": {
          "text":{
          "value": "surprize",
            "fuzziness": 10
          }
        }
      }
    }
    
    
    
    GET /my_index/my_type/_search 
    {
      "query": {
        "match": {
          "text": {
            "query": "SURPIZE ME",
            "fuzziness": "AUTO"
          }
        }
      }
    }
    GET /my_index/my_type/_search 
    {
      "query": {
        "match": {
         "text":{
           "query": "SURPIZE ME"
           , "fuzziness": "AUTO",
           "operator": "and"
         }
        }
      }
    }
    GET /my_index/_analyze
    {
      "text": "男子偷上万元发红包求交女友 被抓获时仍然单身",
      "analyzer": "ik_max_word"
    }
    
    GET /my_index/my_type/_search 
    {
      "query": {
        "match": {
          "text": "16岁少女结婚好还是单身好?"
        }
      }
    }
    
    PUT /my_index 
    {
      "mappings": {
        "my_type": {
          "properties": {
            "text": {
              "type": "text",
              "analyzer": "ik_max_word"
            }
          }
        }
      }
    }
    
    POST /my_index/my_type/_bulk
    { "index": { "_id": "1"} }
    { "text": "男子偷上万元发红包求交女友 被抓获时仍然单身" }
    { "index": { "_id": "2"} }
    { "text": "16岁少女为结婚“变”22岁 7年后想离婚被法院拒绝" }
    { "index": { "_id": "3"} }
    { "text": "深圳女孩骑车逆行撞奔驰 遭索赔被吓哭(图)" }
    { "index": { "_id": "4"} }
    { "text": "女人对护肤品比对男票好?网友神怼" }
    { "index": { "_id": "5"} }
    { "text": "为什么国内的街道招牌用的都是红黄配?" }
    
    
    DELETE my_index
    
    
    
    PUT /my_index 
    {
      "mappings": {
        "my_type": {
          "properties": {
            "text": {
              "type": "text",
              "analyzer": "ik_max_word"
            }
          }
        }
      }
    }
    POST /my_index/my_type/_bulk
    { "index": { "_id": "1"} }
    { "text": "男子偷上万元发红包求交女友 被抓获时仍然单身" }
    { "index": { "_id": "2"} }
    { "text": "16岁少女为结婚“变”22岁 7年后想离婚被法院拒绝" }
    { "index": { "_id": "3"} }
    { "text": "深圳女孩骑车逆行撞奔驰 遭索赔被吓哭(图)" }
    { "index": { "_id": "4"} }
    { "text": "女人对护肤品比对男票好?网友神怼" }
    { "index": { "_id": "5"} }
    { "text": "为什么国内的街道招牌用的都是红黄配?" }
    
    GET /my_index/my_type/_search 
    {
      "query": {
        "match": {
          "text": "16岁少女结婚好还是单身好?"
        }
      }
    }
    GET /my_index/_analyze
    {
      "text":"16岁少女结婚好还是单身好",
       "analyzer": "ik_max_word"
    }
    
    
    PUT /tvs
    {
        "mappings": {
            "sales": {
                "properties": {
                    "price": {
                        "type": "long"
                    },
                    "color": {
                        "type": "keyword"
                    },
                    "brand": {
                        "type": "keyword"
                    },
                    "sold_date": {
                        "type": "date"
                    }
                }
            }
        }
    }
    GET /tvs/sales/_search
    {
    "size": 0, 
      "aggs": {
        "popular_colors": {
         "terms": {
           "field": "color"
         }
        }
      }
    }
    GET /tvs/sales/_search
    {
       "size" : 0,
       "aggs": {
          "colors": {
             "terms": {
                "field": "color"
             },
             "aggs": { 
                "avg_price": { 
                   "avg": {
                      "field": "price" 
                   }
                }
             }
          }
       }
    }
    GET /tvs/sales/_search
    {
      "size": 0,
      "aggs": {
        "colors": {
         "terms": {
           "field": "color"
         },
         "aggs": {
           "avg_price": {
            "avg": {
              "field": "price"
            }
           }
         }
        }
      }
    }
    
    
    
    
    
    GET /tvs/sales/_search
    {
      "size": 0,
      "aggs": {
        "group_by_color": {
          "terms": {
            "field": "color"
          },
          "aggs": {
            "color_avg_price": {
              "avg": {
                "field": "price"
              }
            },
            "group_by_brand": {
              "terms": {
                "field": "brand"
              },
              "aggs": {
                "brand_avg_price": {
                  "avg": {
                    "field": "price"
                  }
                }
              }
            }
          }
        }
      }
    }
    GET /tvs/sales/_search 
    {
      "size": 0,
      "aggs": {
        "group_by_color": {
          "terms": {
            "field": "color"
          },
          "aggs": {
            "color_avg_price": {
              "avg": {
                "field": "price"
              }
            },
            "group_by_brand": {
              "terms": {
                "field": "brand"
              },
              "aggs": {
                "brand_avg_price": {
                  "avg": {
                    "field": "price"
                  }
                }
              }
            }
          }
        }
      }
    }
    GET /tvs/sales/_search
    {
      "size": 0,
      "aggs": {
        "colors": {
          "terms": {
            "field": "color"
          },
          "aggs": {
            "avg_price": {
              "avg": {
                "field": "price"
              }
            },
            "min_price": {
              "min": {
                "field": "price"
              }
            },
            "max_price": {
              "max": {
                "field": "price"
              }
            },
            "sum_price": {
              "sum": {
                "field": "price"
              }
            }
          }
        }
      }
    }
    GET /tvs/sales/_search
    {
      "size": 0, 
      "aggs": {
        "colors": {
         "terms": {
           "field": "color"
           
         },
         "aggs": {
           "avg_price": {
             "avg": {
               "field": "price"
             }
            },
            "max_price":{
              "max": {
                "field": "price"
              }
            },
            "min_price":{
              "min": {
                "field": "price"
              }
            },
            "sum_price":{
              "sum": {
                "field": "price"
              }
            }
         }
        }
      }
    }
    
    GET /tvs/sales/_search
    {
       "size" : 0,
       "aggs":{
          "price":{
             "histogram":{ 
                "field": "price",
                "interval": 2000
             },
             "aggs":{
                "revenue": {
                   "sum": { 
                     "field" : "price"
                   }
                 }
             }
          }
       }
    }
    GET /tvs/sales/_search
    {
      "size": 0,
      "aggs": {
        "price": {
          "histogram": {
            "field": "price",
            "interval": 2000
          },
          "aggs": {
            "revenue":{
              "sum": {
                "field": "price"
              }
            }
          }
        }
      }
    }
    GET /tvs/sales/_search
    {
      "size": 0,
      "aggs": {
        "sales": {
         "date_histogram": {
           "field": "date",
           "interval": "month",
           "format": "yyyy-MM-dd",
           "min_doc_count": 0,
           "extended_bounds":{
               "min" : "2016-01-01",
                "max" : "2017-12-31"
           }
         }
        }
      }
    }
    
    GET /tvs/sales/_search 
    {
      "size": 0,
      "aggs": {
        "group_by_sold_date": {
          "date_histogram": {
            "field": "sold_date",
            "interval": "quarter",
            "format": "yyyy-MM-dd",
            "min_doc_count": 0,
            "extended_bounds": {
              "min": "2016-01-01",
              "max": "2017-12-31"
            }
          },
          "aggs": {
            "group_by_brand": {
              "terms": {
                "field": "brand"
              },
              "aggs": {
                "sum_price": {
                  "sum": {
                    "field": "price"
                  }
                }
              }
            },
            "total_sum_price": {
              "sum": {
                "field": "price"
              }
            }
          }
        }
      }
    }
    
    GET /tvs/sales/_search 
    {
      "size":0,
      "aggs": {
        "group_by_sold_date": {
        "date_histogram": {
          "field": "date",
          "interval": "quarter",
          "min_doc_count": 0,
          "extended_bounds":{
            "min": "2016-01-01",
              "max": "2017-12-31"
          }
        }, 
        "aggs": {
          "group_by_brand": {
           "terms": {
             "field": "brand"
           },
           "aggs": {
             "sum_price": {
               "sum": {
                 "field": "price"
               }
             }
           }
          },
          "total_price":{
            "sum": {
              "field": "price"
            }
          }
        }
        }
      }
    }
    GET /tvs/sales/_search 
    {
      "size": 0, 
      "query": {
        "constant_score": {
          "filter": {
            "range": {
              "price": {
                "gte": 1200
              }
            }
          }
        }
      },
      "aggs": {
        "avg_price": {
          "avg": {
            "field": "price"
          }
        }
      }
    }
    
    GET /tvs/sales/_search
    {
      "size" : 0,
      "aggs" : {
          "months" : {
            "date_histogram": {
              "field": "sold_date",
              "interval": "month"
            },
            "aggs": {
              "distinct_colors" : {
                  "cardinality" : {
                    "field" : "brand"
                  }
              }
            }
          }
      }
    }
    #qu'chong去重 
    GET /tvs/sales/_search
    {
      "aggs": {
        "months": {
          "date_histogram": {
            "field": "sold_date",
            "interval": "month"
          
          },
          "aggs": {
            "distinct_colors": {
             "cardinality": {
               "field": "brand",
               "precision_threshold": 100
             }
            }
          }
        }
      }
    }
    
    
    
    POST /website/logs/_bulk
    { "index": {}}
    { "latency" : 105, "province" : "江苏", "timestamp" : "2016-10-28" }
    { "index": {}}
    { "latency" : 83, "province" : "江苏", "timestamp" : "2016-10-29" }
    { "index": {}}
    { "latency" : 92, "province" : "江苏", "timestamp" : "2016-10-29" }
    { "index": {}}
    { "latency" : 112, "province" : "江苏", "timestamp" : "2016-10-28" }
    { "index": {}}
    { "latency" : 68, "province" : "江苏", "timestamp" : "2016-10-28" }
    { "index": {}}
    { "latency" : 76, "province" : "江苏", "timestamp" : "2016-10-29" }
    { "index": {}}
    { "latency" : 101, "province" : "新疆", "timestamp" : "2016-10-28" }
    { "index": {}}
    { "latency" : 275, "province" : "新疆", "timestamp" : "2016-10-29" }
    { "index": {}}
    { "latency" : 166, "province" : "新疆", "timestamp" : "2016-10-29" }
    { "index": {}}
    { "latency" : 654, "province" : "新疆", "timestamp" : "2016-10-28" }
    { "index": {}}
    { "latency" : 389, "province" : "新疆", "timestamp" : "2016-10-28" }
    { "index": {}}
    { "latency" : 302, "province" : "新疆", "timestamp" : "2016-10-29" }
    
    
    
    PUT /website
    {
        "mappings": {
            "logs": {
                "properties": {
                    "latency": {
                        "type": "long"
                    },
                    "province": {
                        "type": "keyword"
                    },
                    "timestamp": {
                        "type": "date"
                    }
                }
            }
        }
    }
    
    GET website/_search
    {
       "size": 0,
      "aggs": {
        "latency_time": {
          "percentiles": {
            "field": "latency",
            "percents": [
              50,
              75,
              99
            ]
          }
        },
        "avg_time": {
          "avg": {
            "field": "latency"
          }
        }
      }
    }
    GET /website/logs/_search 
    {
      "size": 0,
      "aggs": {
        "latency_percentiles": {
          "percentiles": {
            "field": "latency",
            "percents": [
              50,
              95,
              99
            ]
          }
        },
        "latency_avg": {
          "avg": {
            "field": "latency"
          }
        }
      }
    }
    
    GET /website/logs/_search 
    {
      "size": 0,
      "aggs": {
        "group_by_province": {
          "terms": {
            "field": "province"
          },
          "aggs": {
            "latency_percentile_ranks": {
              "percentile_ranks": {
                "field": "latency",
                "values": [
                  200,
                  1000
                ]
              }
            }
          }
        }
      }
    }
    
    
    
    GET /_stats/fielddata?fields=*
    
    GET /_nodes/stats/indices/fielddata?fields=*
    
    GET /_nodes/stats/indices/fielddata?level=indices&fields=*
    
    
    
    POST /test_index/_mapping/test_type
    {
      "properties": {
        "test_field": {
          "type": "string",
          "fielddata": {
            "loading" : "eager_global_ordinals" 
          }
        }
      }
    }
    
    POST /test_index/_mapping/test_type
    {
      "properties": {
        "test_field": {
          "type": "string",
          "fielddata": {
            "loading" : "eager" 
          }
        }
      }
    }
    PUT /website/users/1 
    {
      "name":     "小鱼儿",
      "email":    "xiaoyuer@sina.com",
      "birthday":      "1980-01-01"
    }
    
    PUT /website/blogs/1
    {
      "title":    "我的第一篇博客",
      "content":     "这是我的第一篇博客,开通啦!!",
      "userId":     1 
    }
    
    GET website/blogs/_search
    GET /website/users/_search 
    {
      "query": {
        "term": {
          "name.keyword": {
            "value": "小鱼儿"
          }
        }
      }
    }
    
    GET /website/blogs/_search 
    {
      "query": {
        "constant_score": {
          "filter": {
            "terms": {
              "userId": [
                1
              ]
            }
          }
        }
      }
    }
    GET /website/blogs/_search 
    {
      
      "query": {
        "constant_score": {
          "filter": {
            "terms": {
              "userId": [
                1
              ]
            }
          }
        }
      }
    }
    DELETE website
    
    
    PUT  website/users/1
    {
      "name":"小鱼儿",
      "email":"xiaoyuer@sina.com",
      "birthday":"1989-01-01"
    }
    PUT  website/blogs/1
    {
      "title":"小鱼儿的第一篇博客",
      "ontent":"大家好,我是小鱼儿。。。",
      "userInfo":{
        "userId":1,
        "userName":"小鱼儿"
      }
    }
    GET /website/blogs/_search 
    {
      "query": {
        "term": {
          "userInfo.userName.keyword": {
            "value": "小鱼儿"
          }
        }
      }
    }
    
    PUT /website/users/3
    {
      "name": "黄药师",
      "email": "huangyaoshi@sina.com",
      "birthday": "1970-10-24"
    }
    
    PUT /website/blogs/3
    {
      "title": "我是黄药师",
      "content": "我是黄药师啊,各位同学们!!!",
      "userInfo": {
        "userId": 1,
        "userName": "黄药师"
      }
    }
    
    PUT /website/users/2
    {
      "name": "花无缺",
      "email": "huawuque@sina.com",
      "birthday": "1980-02-02"
    }
    
    PUT /website/blogs/4
    {
      "title": "花无缺的身世揭秘",
      "content": "大家好,我是花无缺,所以我的身世是。。。",
      "userInfo": {
        "userId": 2,
        "userName": "花无缺"
      }
    }
    
    
    GET /website/blogs/_search 
    {
      "size": 0,
      "aggs": {
        "group_by_name": {
        "terms": {
          "field": "userInfo.userName.keyword"
         },
         "aggs": {
           "top_blogs": {
             "top_hits": {
              "_source": {
                "include": "title"
              },
              "size": 5
             }
           }
         }
        }
      }
    }
    
    GET /website/blogs/_search 
    {
      "size": 0, 
      "aggs": {
        "group_by_username": {
          "terms": {
            "field": "userInfo.userName.keyword"
          },
          "aggs": {
            "top_blogs": {
              "top_hits": {
                "_source": {
                  "include": "title"
                }, 
                "size": 5
              }
            }
          }
        }
      }
    }
    
    DELETE /fs/lock/global
    
    
    
    POST /fs/file/1/_update
    {
      "doc": {
        "name": "README1.txt"
      }
    }
    DELETE /fs/lock/global
    
    
    
    PUT /website/blogs/6
    {
      "title": "花无缺发表的一篇帖子",
      "content":  "我是花无缺,大家要不要考虑一下投资房产和买股票的事情啊。。。",
      "tags":  [ "投资", "理财" ],
      "comments": [ 
        {
          "name":    "小鱼儿",
          "comment": "什么股票啊?推荐一下呗",
          "age":     28,
          "stars":   4,
          "date":    "2016-09-01"
        },
        {
          "name":    "黄药师",
          "comment": "我喜欢投资房产,风,险大收益也大",
          "age":     31,
          "stars":   5,
          "date":    "2016-10-22"
        }
      ]
    }
    
    GET /website/blogs/_search
    {
      "query": {
        "bool": {
          "must": [
            { "match": { "comments.name": "黄药师" }},
            { "match": { "comments.age":  28      }} 
          ]
        }
      }
    }
    
    PUT /website
    {
      "mappings": {
        "blogs": {
          "properties": {
            "comments": {
              "type": "nested", 
              "properties": {
                "name":    { "type": "string"  },
                "comment": { "type": "string"  },
                "age":     { "type": "short"   },
                "stars":   { "type": "short"   },
                "date":    { "type": "date"    }
              }
            }
          }
        }
      }
    }
    
    PUT /website/blogs/1
    {
      "title": "花无缺发表的一篇帖子",
      "content":  "我是花无缺,大家要不要考虑一下投资房产和买股票的事情啊。。。",
      "tags":  [ "投资", "理财" ],
      "comments": [ 
        {
          "name":    "小鱼儿",
          "comment": "什么股票啊?推荐一下呗",
          "age":     28,
          "stars":   4,
          "date":    "2016-09-01"
        },
        {
          "name":    "黄药师",
          "comment": "我喜欢投资房产,风,险大收益也大",
          "age":     31,
          "stars":   5,
          "date":    "2016-10-22"
        }
      ]
    }
    GET /website/blogs/_search
    
    
    GET /website/blogs/_search
    {
      "query": {
        "bool": {
          "must": [
            { "match": { "comments.name": "黄药师" }},
            { "match": { "comments.age":  31      }} 
          ]
        }
      }
    }
    GET /website/blogs/_search
    {
      "query": {
        "bool": {
          "must": [
            {
              "match": {
                "title": "花无缺"
              },
              "nested": {
                "path": "comments",
                "query": {
                  "bool": {
                    "must": [
                      {
                        "match": {
                          "comments.name":"黄药师"
                        }
                      }
                    ]
                  }
                }
              }
            }
          ]
        }
      }
    }
    
    GET /website/blogs/_search 
    {
      "query": {
        "bool": {
          "must": [
            {
              "match": {
                "title": "花无缺"
              }
            },
            {
              "nested": {
                "path": "comments",
                "query": {
                  "bool": {
                    "must": [
                      {
                        "match": {
                          "comments.name": "黄药师"
                        }
                      },
                      {
                        "match": {
                          "comments.age": 31
                        }
                      }
                    ]
                  }
                }
              }
            }
          ]
        }
      }
    }
    
    GET /website/blogs/_search 
    {
      "size": 0, 
      "aggs": {
        "comments_path": {
          "nested": {
            "path": "comments"
          }, 
          "aggs": {
            "group_by_comments_date": {
              "date_histogram": {
                "field": "comments.date",
                "interval": "month",
                "format": "yyyy-MM"
              },
              "aggs": {
                "avg_stars": {
                  "avg": {
                    "field": "comments.stars"
                  }
                }
              }
            }
          }
        }
      }
    }
    GET /website/blogs/_search 
    {
      "size": 0,
      "aggs": {
        "comments_path": {
          "nested": {
            "path": "comments"
          },
          "aggs": {
            "group_by_comments_age": {
              "histogram": {
                "field": "comments.age",
                "interval": 10
              },
              "aggs": {
                "reverse_path": {
                  "reverse_nested": {}, 
                  "aggs": {
                    "group_by_tags": {
                      "terms": {
                        "field": "tags.keyword"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    
    DELETE company
    
    GET /company/_search
    PUT /company
    {
      "mappings": {
        "rd_center": {},
        "employee": {
          "_parent": {
            "type": "rd_center" 
          }
        }
      }
    }
    
    POST /company/rd_center/_bulk
    { "index": { "_id": "1" }}
    { "name": "北京研发总部", "city": "北京", "country": "中国" }
    { "index": { "_id": "2" }}
    { "name": "上海研发中心", "city": "上海", "country": "中国" }
    { "index": { "_id": "3" }}
    { "name": "硅谷人工智能实验室", "city": "硅谷", "country": "美国" }
    
    
    PUT /company/employee/1?parent=1 
    {
      "name":  "张三",
      "birthday":   "1970-10-24",
      "hobby": "爬山"
    }
    
    
    
    
    POST /company/employee/_bulk
    { "index": { "_id": 2, "parent": "1" }}
    { "name": "李四", "birthday": "1982-05-16", "hobby": "游泳" }
    { "index": { "_id": 3, "parent": "2" }}
    { "name": "王二", "birthday": "1979-04-01", "hobby": "爬山" }
    { "index": { "_id": 4, "parent": "3" }}
    { "name": "赵五", "birthday": "1987-05-11", "hobby": "骑马" }
    GET /company/rd_center/_search
    {
      "query": {
        "has_child": {
          "type": "employee",
          "query": {
            "range": {
              "birthday": {
                "gte": "1980-01-01"
              }
            }
          }
        }
      }
    }
    
    GET /company/rd_center/_search
    {
      "query": {
        "has_child": {
          "type": "employee",
          "query": {
            "range": {
              "birthday": {
                "gte": "1980-01-01"
              }
            }
          }
        }
      }
    }
    GET /company/rd_center/_search
    {
      "query": {
        "has_child": {
          "type": "employee",
          "query": {
            "match": {
              "name": "张三"
            }
          }
        }
      }
    }
    
    GET /company/rd_center/_search
    {
      "query": {
        "has_child": {
          "type": "employee",
          "min_children": 2, 
          "query": {
            "match_all": {}
          }
        }
      }
    }
    GET /company/employee/_search 
    {
      "query": {
        "has_parent": {
          "parent_type": "rd_center",
          "query": {
            "term": {
              "country.keyword":"中国"
            }
          }
        }
      }
    }
    GET /company/rd_center/_search 
    {
      "size": 0,
      "aggs": {
        "group_by_country": {
          "terms": {
            "field": "country.keyword"
          },
          "aggs": {
            "group_by_child_employee": {
              "children": {
                "type": "employee"
              },
              "aggs": {
                "group_by_hobby": {
                  "terms": {
                    "field": "hobby.keyword"
                  }
                }
              }
            }
          }
        }
      }
    }
    GET /company/rd_center/_search 
    {
      "aggs": {
        "group_by_country": {
          "terms": {
            "field": "country.keyword"
          },
          "aggs": {
            "group_by_child_employee": {
            "children": {
              "type": "employee"
            },
            "aggs": {
              "group_by_hobby": {
               "terms": {
                 "field": "hobby.keyword"
                
               }
              }
            }
            }
          }
        }
      }
    }
    
    DELETE company
    PUT /company
    {
      "mappings": {
        "country": {},
        "rd_center": {
          "_parent": {
            "type": "country" 
          }
        },
        "employee": {
          "_parent": {
            "type": "rd_center" 
          }
        }
      }
    }
    
    POST /company/country/_bulk
    { "index": { "_id": "1" }}
    { "name": "中国" }
    { "index": { "_id": "2" }}
    { "name": "美国" }
    
    
    POST /company/rd_center/_bulk
    { "index": { "_id": "1", "parent": "1" }}
    { "name": "北京研发总部" }
    { "index": { "_id": "2", "parent": "1" }}
    { "name": "上海研发中心" }
    { "index": { "_id": "3", "parent": "2" }}
    { "name": "硅谷人工智能实验室" }
    
    
    PUT /company/employee/1?parent=1&routing=1
    {
      "name":  "张三",
      "dob":   "1970-10-24",
      "hobby": "爬山"
    }
    
    
    GET /company/country/_search
    {
      "query": {
        "has_child": {
          "type": "rd_center",
          "query": {
            "has_child": {
              "type": "employee",
              "query": {
                "match": {
                  "hobby": "爬山"
                }
              }
            }
          }
        }
      }
    }
    GET /company/country/_search
    {
      "query": {
        "has_child": {
          "type": "rd_center",
          "query": {
            "has_child": {
              "type": "employee",
              "query": {
                "match": {
                  "hobby": "爬山"
                }
              }
            }
          }
        }
      }
    }
    DELETE blog_website
    PUT /blog_website
    {
      "mappings": {
        "blogs": {
          "properties": {
            "title": {
              "type": "text",
              "analyzer": "ik_max_word"
            },
            "content": {
              "type": "text",
              "analyzer": "ik_max_word"
            }
          }
        }
      }
    }
    
    PUT /blog_website/blogs/1
    {
      "title": "我的第一篇博客",
      "content": "大家好,这是我写的第一篇博客,特别喜欢这个博客网站!!!"
    }
    GET blog_website/blogs/_search
    {
      "query": {
        "match": {
          "title": "博客"
        }
      
      },
      "highlight": {
        "fields": {
          "title":{}
        }
      }
    }
    
    
    GET /blog_website/blogs/_search 
    {
      "query": {
        "bool": {
          "should": [
            {
              "match": {
                "title": "博客"
              }
            },{
              "match": {
                "content": "博客"
              }
            }
          ]
        }
        
      },
      "highlight": {
        "fields": {
          "title":{},
          "content":{}
        }
      }
    }
    GET /blog_website/blogs/_search/template
    {
      "inline":{
        "query":{
        "match":{
          "{{field}}":"{{value}}"
        }
      }
      },"params": {
        "field":"title",
        "value":"博客"
      }
    }
    
    
    GET /blog_website/blogs/_search/template
    {
      "inline": "{"query": {"match": {{#toJson}}matchCondition{{/toJson}}}}",
      "params": {
        "matchCondition": {
          "title": "博客"
        }
      }
    }
    GET /blog_website/blogs/_search/template
    {
      "inline": {
        "query": {
          "match": {
            "title": "{{#join delimiter=' '}}titles{{/join delimiter=' '}}"
          }
        }
      },
      "params": {
        "titles": ["博客", "网站"]
      }
    }
    
    #  delete news_website
    
    
    
    PUT /news_website
    {
      "mappings": {
        "news" : {
          "properties" : {
            "title" : {
              "type": "text",
              "analyzer": "ik_max_word",
              "fields": {
                "suggest" : {
                  "type" : "completion",
                  "analyzer": "ik_max_word"
                }
              }
            },
            "content": {
              "type": "text",
              "analyzer": "ik_max_word"
            }
          }
        }
      }
    }
    
    PUT /news_website/news/1
    {
      "title": "大话西游电影",
      "content": "大话西游的电影时隔20年即将在2017年4月重映"
    }
    PUT /news_website/news/2
    {
      "title": "大话西游小说",
      "content": "某知名网络小说作家已经完成了大话西游同名小说的出版"
    }
    PUT /news_website/news/3
    {
      "title": "大话西游手游",
      "content": "网易游戏近日出品了大话西游经典IP的手游,正在火爆内测中"
    }
    PUT /news_website
    {
      "mappings": {
        "news" : {
          "properties" : {
            "title" : {
              "type": "text",
              "analyzer": "ik_max_word",
              "fields": {
                "suggest" : {
                  "type" : "completion",
                  "analyzer": "ik_max_word"
                }
              }
            },
            "content": {
              "type": "text",
              "analyzer": "ik_max_word"
            }
          }
        }
      }
    }
    PUT /news_website2
    {
      "mappings": {
        "news":{
          "properties": {
            "title":{
              "type": "text",
              "analyzer": "ik_max_word",
              "fields": {
                "suggest":{
                  "type": "completion",
                  "analyzer": "ik_max_word"
                }
              }
            },
            "content":{
              "type": "text",
              "analyzer": "ik_max_word",
              "fields": {
                "suggest":{
                  "type": "completion",
                  "analyzer": "ik_max_word"
                }
              }
            }
          }
        }
      }
    }
    POST /news_website2/news/3
    {
    "title": "大话西游电影",
      "content": "大话西游的电影时隔20年即将在2017年4月重映"
    }
    GET /news_website2/news/_search
    {
      "query": {
        "match": {
          "title": "西游"
        }
      },
      "explain": true
    }
    
    
    GET /news_website2/news/_search
    {
      "suggest":{
        "suggest":{
          "prefix":"大话西游",
          "completion":{
            "field":"title.suggest"
          }
        }
      }
    }
    
    #
    GET /news_website/news/_search
    {
      "query": {
        "prefix": {
          "title": {
            "value": "大话西游"
          }
        }
      },
      "_source": ["title","content"],
      "explain": true
    }
    
    GET /news_website/news/_search
    {
      "suggest": {
        "my-suggest" : {
          "prefix" : "大话西游",
          "completion" : {
            "field" : "title.suggest"
          }
        }
      }
    }
    DELETE my_index
    PUT my_index
    {
      "mappings": {
        "my_type": {
          "dynamic_templates": [
            {
              "integers": {
                "match_mapping_type": "long",
                "mapping": {
                  "type": "integer"
                }
              }
            },
            {
              "strings": {
                "match_mapping_type": "string",
                "mapping": {
                  "type": "text",
                  "fields": {
                    "raw": {
                      "type": "keyword",
                      "ignore_above": 500
                    }
                  }
                }
              }
            }
          ]
        }
      }
    }
    
    PUT /my_index/my_type/1
    {
      "test_long": 1,
      "test_string": "hello world"
    }
    
    
    GET my_index/_mapping/my_type
    
    PUT /my_index 
    {
      "mappings": {
        "my_type": {
          "dynamic_templates": [
            {
              "string_as_integer": {
                "match_mapping_type": "string",
                "match": "long_*",
                "unmatch": "*_text",
                "mapping": {
                  "type": "integer"
                }
              }
            }
          ]
        }
      }
    }
    
    DELETE car_shop
    PUT /car_shop
    {
        "mappings": {
            "cars": {
                "properties": {
                    "brand": {
                        "type": "text",
                        "analyzer": "ik_max_word",
                        "fields": {
                            "raw": {
                                "type": "keyword"
                            }
                        }
                    },
                    "name": {
                        "type": "text",
                        "analyzer": "ik_max_word",
                        "fields": {
                            "raw": {
                                "type": "keyword"
                            }
                        }
                    }
                }
            }
        }
    }
    
    GET car_shop/_search
    
    
    PUT /car_shop/cars/2
    {
        "brand": "奔驰",
        "name": "奔驰C200",
        "price": 350000,
        "produce_date": "2017-01-05"
    }
    
    
    
    PUT /car_shop/sales/1
    {
        "brand": "宝马",
        "name": "宝马320",
        "price": 320000,
        "produce_date": "2017-01-01",
        "sale_price": 300000,
        "sale_date": "2017-01-21"
    }
    
    PUT /car_shop/sales/2
    {
        "brand": "宝马",
        "name": "宝马320",
        "price": 320000,
        "produce_date": "2017-01-01",
        "sale_price": 300000,
        "sale_date": "2017-01-21"
    }
    
    
    GET /car_shop/sales/_search
    
    DELETE products
    
    PUT products
    {
      "settings": {
        "number_of_shards": 1
      }
    }
    
    
    
    POST /products/products/_bulk
    { "index": { "_id": 1 }}
    { "productID" : "XHDK-A-1293-#fJ3","desc":"iPhone" }
    { "index": { "_id": 2 }}
    { "productID" : "KDKE-B-9947-#kL5","desc":"iPad" }
    { "index": { "_id": 3 }}
    { "productID" : "JODL-X-1937-#pV7","desc":"MBP" }
    POST _analyze
    {
      "text":"iPhone"
    }
    
    
    GET /products/products/_search
    {
      "query": {
       "term": {
         "desc.keyword": {
           "value": "iPhone"
         }
       }
      }
    }
    GET /products/products/_search
    {
      "explain": true, 
      "query": {
        "constant_score": {
          "filter": {
            "term": {
              "desc.keyword": "iPhone"
            }
          }
         
        }
      }
    }
    
    
    
    
    
    
    PUT /website 
    {
      "mappings": {
        "article": {
          "properties": {
            "title": {
              "type": "text",
              "fields": {
                "raw": {
                  "type": "string",
                  "index": "not_analyzed"
                }
              },
              "fielddata": true
            },
            "content": {
              "type": "text"
            },
            "post_date": {
              "type": "date"
            },
            "author_id": {
              "type": "long"
            }
          }
        }
      }
    }
    
    PUT /blogs/blogs/1
    {
        "title": "Quick brown rabbits",
        "body":  "Brown rabbits are commonly see."
    }
    
    
    PUT /blogs/blogs/2
    {
        "title": "Keeping pets healthy",
        "body":  "My quick brown fox eats rabbits on a regular basis."
    }
    
    POST /blogs/blogs/_search
    {
      "query": {
        "bool": {
          "should": [
            {
              "match": {
                "title": "Brown fox"
              }
            },
            {
              "match": {
                "body": "Brown fox"
              }
            }
          ]
        }
      }
    }
    
    GET /blogs/blogs/_search
    {
      "query": {
        "dis_max": {
          "tie_breaker": 0.7,
          "boost": 1.2,
          "queries": [
            {
              "match": {
                "title": "Brown fox"
              }
            },
            {
              "match": {
                "body": "Brown fox"
              }
            }
          ]
        }
      }
    }
    POST blogs/blogs/_search
    {
        "query": {
            "dis_max": {
                "queries": [
                    { "match": { "title": "Quick pets" }},
                    { "match": { "body":  "Quick pets" }}
                ],
                "tie_breaker": 0.2
            }
        }
    }
    GET articles/_search
    DELETE articles
    
    PUT articles
    {
      "mappings": {
         "articles"{
         "properties": {
          "title_completion":{
            "type": "completion"
          }
         } 
        }
      }
    }
    
    PUT /articles 
    {
      "mappings": {
        "articles": {
          "properties": {
          "title_completion":{
            "type": "completion"
          }
         } 
        }
      }
    }
    
    POST articles/articles/_bulk
    { "index" : { } }
    { "title_completion": "lucene is very cool"}
    { "index" : { } }
    { "title_completion": "Elasticsearch builds on top of lucene"}
    { "index" : { } }
    { "title_completion": "Elasticsearch rocks"}
    { "index" : { } }
    { "title_completion": "elastic is the company behind ELK stack"}
    { "index" : { } }
    { "title_completion": "Elk stack rocks"}
    { "index" : {} }
    
    POST articles/_search?pretty
    {
      "size": 0,
      "suggest": {
        "article-suggester": {
          "prefix": "e ",
          "completion": {
            "field": "title_completion"
          }
        }
      }
    }
    GET articles/articles/_search
    {
      "explain": true, 
      "suggest":{
        "articles-suggest":{
          "prefix":"elk",
          "completion":{
            "field":"title_completion"
          }
        }
      }
    }
    
    
    PUT /articles 
    {
      "mappings": {
        "articles": {
          "properties": {
          "title_completion":{
            "type": "completion"
          }
         } 
        }
      }
    }
    DELETE comments
    PUT comments
    PUT comments/_mapping
    
    
    PUT comments
    {
      "mappings": {
        "comments":{
           "properties": {
        "comment_autocomplete":{
          "type": "completion",
          "contexts":[{
            "type":"category",
            "name":"comment_category"
          }]
        }
      }
        }
      }
    }
    DELETE comments
    
    
    GET comments/_search
    
    PUT comments
    {
      "mappings": {
        "comments": {
          "properties": {
            "comment_autocomplete": {
              "type": "completion",
              "contexts": [
                {
                  "type": "category",
                  "name": "comment_category"
                }
              ]
            }
          }
        }
      }
    }
    
    
    
    POST comments/comments/1
    {
      "comment":"I love the star war movies",
      "comment_autocomplete":{
        "input":["star wars"],
        "contexts":{
          "comment_category":"movies"
        }
      }
    }
    POST comments/comments/2
    {
      "comment":"Where can I find a Starbucks",
      "comment_autocomplete":{
        "input":["starbucks"],
        "contexts":{
          "comment_category":"coffee"
        }
      }
    }
    GET comments/_search
    {
      "size": 0, 
      "suggest": {
        "my_suggest": {
          "prefix": "sta",
          "completion":{
            "field":"comment_autocomplete",
            "contexts":{
              "comment_category":"movies"
            }
          }
        }
      }
    }
    
    GET comments/_search
    {
      "size": 0, 
      "suggest": {
        "my_suggest": {
          "prefix": "sta",
          "completion":{
            "field":"comment_autocomplete",
            "contexts":{
              "comment_category":"coffee"
            }
          }
        }
      }
    }
    
    
    
    
    
    PUT _snapshot/my_hdfs_repository/snapshot_4
    {
        "indices": "my_index",
        "ignore_unavailable": true,
        "include_global_state": false,
        "partial": true
    }
    
    
    
    
    GET /_cat/health?v
    
    GET _cluster/health
    
    GET /_cat/indices?v
    
    
    GET /_cat/nodes?v
    
    
    
    
    POST /car/transactions/_bulk
    { "index": {}}
    { "price" : 10000, "color" : "red", "make" : "honda", "sold" : "2014-10-28" }
    { "index": {}}
    { "price" : 20000, "color" : "red", "make" : "honda", "sold" : "2014-11-05" }
    { "index": {}}
    { "price" : 30000, "color" : "green", "make" : "ford", "sold" : "2014-05-18" }
    { "index": {}}
    { "price" : 15000, "color" : "blue", "make" : "toyota", "sold" : "2014-07-02" }
    { "index": {}}
    { "price" : 12000, "color" : "green", "make" : "toyota", "sold" : "2014-08-19" }
    { "index": {}}
    { "price" : 20000, "color" : "red", "make" : "honda", "sold" : "2014-11-05" }
    { "index": {}}
    { "price" : 80000, "color" : "red", "make" : "bmw", "sold" : "2014-01-01" }
    { "index": {}}
    { "price" : 25000, "color" : "blue", "make" : "ford", "sold" : "2014-02-12" }
    
    #an'yan'se'fen'zu安颜色分组
    
    GET /car/transactions/_search
    {
       "size": 0,
      "aggs": {
        "group_by_color": {
         "terms": {
           "field": "color.keyword"
         }
        }
      }
    }
    
    
    #先按颜色分组后计算平均价格 
    
    #select color, count(color) as cnt, avg(price) as avg_price from cars group by color order by cnt desc;
    GET /car/transactions/_search
    {
      "size": 0, 
      "aggs": {
        "group_by_color": {
          "terms": {
           "field": "color.keyword"
         },
         "aggs": {
           "avg_color": {
            "avg": {
              "field": "price"
            }
           }
         }
        }
        
      }
    }
    
    
    
    #统计每种颜色汽车制造商的分布dsl实现
    
    #select color, make from cars order by color;
    GET /car/transactions/_search
    {
      "size": 0,
      "aggs": {
        "group_by_color": {
          "terms": {
            "field": "color.keyword"
          },
          "aggs": {
            "group_by_make": {
              "terms": {
                "field": "make.keyword"
              }
            }
          }
        }
      }
    }
    
    
    GET _stats/fielddata?human&fields=my_join_field
    
    GET _nodes/stats/indices/fielddata?human&fields=my_join_field
    
    
    
    #统计每个制造商的最低、最高价格
    
    
    #select make, min(price) as min_price, max(price) as max_price from cars group by make;
    
    
    GET /car/transactions/_search
    {
       "size": 0,
      "aggs": {
        "group_by_make": {
         "terms": {
           "field": "make.keyword"
         },
         "aggs": {
          "min_price":{
            "min": {
              "field": "price"
            }
          },
          "max_price":{
            "max": {
              "field": "price"
            }
          }
         }
        }
      }
    }
    #select *, avg(price) from cars where period_diff(date_format(now() , '%Y%m') , date_format(sold, '%Y%m')) > 30
    #and make = "ford";
    GET /car/transactions/_search
    {
      "size": 0,
      "aggs": {
        "group_by_price": {
          "histogram": {
            "field": "price",
            "interval": 20000
          },
          "aggs": {
            "revenue": {
              "sum": {
                "field": "price"
              }
            }
          }
        }
      }
    }
    GET /car/transactions/_search
    
    GET /car/transactions/_search
    {
      "size": 0, 
      "aggs": {
       "group_by_data":{
         "date_histogram": {
           "field": "sold",
           "interval": "month",
           "format": "yyyy-MM-dd"
         }
       }
      }
    }
    
    
    
    GET /car/transactions/_search
    {
      "size": 0,
      "aggs": {
        "sales": {
          "date_histogram": {
            "field": "sold",
            "interval": "month",
            "format": "yyyy-MM-dd",
            "min_doc_count": 0,
            "extended_bounds": {
              "min": "2014-01-01",
              "max": "2014-12-31"
            }
          }
        }
      }
    }
    
    GET /car/transactions/_search
    {
      "size": 0, 
      "query": {
        "match": {
          "make.keyword": "ford"
        }
      },
      "aggs": {
        "colors": {
          "terms": {
            "field": "color.keyword"
          }
        }
      }
    }
    
    GET /car/transactions/_search
    {
      "size": 0,
      "query": {
        "match": {
          "make.keyword": "ford"
        }
      },
      "aggs": {
        "single_avg_price": {
          "avg": {
            "field": "price"
          }
        },
        "all": {
          "global": {},
          "aggs": {
            "avg_price": {
              "avg": {
                "field": "price"
              }
            }
          }
        }
      }
    }
    
    GET /car/transactions/_search
    {
      "query": {
        "match": {
          "make": "ford"
        }
      },
      "aggs":{
        "aggs_global":{
          "filter":{
            "range": {
              "price": {
                "gte": 20000,
                "lte": 250000
              }
            }
          },
          "aggs": {
            "avg_price": {
              "avg": {
                "field": "price"
              }
            }
          }
        }
      }
    }
    
    GET /car/transactions/_search
    {
      "query": {
        "match": {
          "make": "ford"
        }
      },
      "post_filter": {
        "term": {
          "color.keyword": "green"
        }
      },
      "aggs": {
        "group_by_price": {
       "terms": {
         "field": "color.keyword"
       }
        }
      }
    }
    
    #post_filter 会过滤搜索结果,只展示绿色 ford 汽车。这在查询执行过 后 发生,所以聚合不受影响。
    
    
    GET /car/transactions/_search
    {
      "size": 0, 
      "aggs": {
       "group_by_color":{
         "terms": {
           "field": "color.keyword",
           "order": {
             "_term": "asc"
           }
         }
       }
      }
    }
    
    
    GET /car/transactions/_search
    {
      "size": 0,
      "aggs": {
        "colors": {
          "terms": {
            "field": "color.keyword",
            "order": {
              "_count": "asc"
            }
          }
        }
      }
    }
    
    #按照 汽车颜色分组,再求平均价格,价格升序
    
    GET /car/transactions/_search
    {
      "size": 0,
      "aggs": {
        "group_by_colors": {
          "terms": {
            "field": "color.keyword",
            "order": {
              "_term": "asc"
            }
          },
          "aggs": {
            "avg_price": {
              "avg": {
                "field": "price"
              }
            }
          }
        }
      }
    }
    GET /car/transactions/_search
    {
      "size": 0, 
      "aggs": {
        "distinct_colors":{
          "cardinality": {
            "field": "color.keyword"
          }
        }
      }
    }
    
    
    GET _nodes/hot_threads
    
    
    
    GET /_cat/thread_pool?v
    
    
    #HDFS 数据恢复 
    PUT _snapshot/my_hdfs_repository/snapshot_6
    {
      "indices": "my_index",
        "ignore_unavailable": true,
        "include_global_state": false,
        "partial": true
    }
    
    
    DELETE my_index
    
    GET my_index/_search
    
    POST /_snapshot/my_hdfs_repository/snapshot_6/_restore?pretty
    
    
    GET my_index/_search
    
    
    GET /_snapshot/my_hdfs_repository
  • 相关阅读:
    2019 Multi-University Training Contest 4
    AC自动机
    trie
    Contest1802
    蓝桥杯-某电视台举办了低碳生活大奖赛
    蓝桥杯-有一群海盗(不多于20人),在船上比拼酒量
    蓝桥杯-福尔摩斯到某古堡探险
    蓝桥杯-标题:字符串比较
    蓝桥杯-题目:猜算式
    蓝桥杯-标题:算年龄
  • 原文地址:https://www.cnblogs.com/wangchuanfu/p/11558340.html
Copyright © 2011-2022 走看看