elasticsearch入门及logstash工具使用

elasticsearch入门
索引创建原则:    
1.类似的数据放在一个索引,非类似的数据放不同索引;
2.index中包含了很多类似的document,这些document的fields很大一部分是相同的;
3.索引名称必须是小写的,不能用下划线开头

指定文档id插入用put
自动产生文档id插入用post
直接修改使用POST方法,同时指定id并在最后添加_update;
删除用delete
直接查询id或索引或类型用get
条件查询需要使用post,同时还有指令_search
启动Elasticsearch:bin/elasticsearch.bat
检查是否启动成功:http://localhost:9200/?pretty
服务默认端口 9300 Web 管理平台端口 9200

将历史数据从DB中(MYSQL)中最终写入到ES中有三种方案 :
第一种:写程序,链接MYSQL,批量的写入kakfa中,后续在现有逻辑已经完成,可以好low啊 而且麻烦;
第二种:使用kafka的connect 从 mysql 导入 kafka ,kafka的consumer 程序写入ES中;
第三种:直接从数据库中写入 ES中,最直接 最省事。
第三种方案认为靠谱的实现方式有两种A 使用ElasticSearch-jdbc 组件;B:使用logstash-jdbc 插件

在ElasticSearch索引中,对应于CRUD中的“创建”和“更新” - 如果对具有给定类型的文档进行索引,并且要插入原先不存在的ID。 如果具有相同类型和ID的文档已存在,则会被覆盖。原文出自【易百教程】,商业转载请联系作者获得授权,非商业请保留原文链接:https://www.yiibai.com/elasticsearch/elasticsearch-getting-start.html
我们对REST API创建一个PUT请求到一个由索引名称,类型名称和ID组成的URL。 也就是:http://localhost:9200/<index>/<type>/[<id>]原文出自【易百教程】,商业转载请联系作者获得授权,非商业请保留原文链接:https://www.yiibai.com/elasticsearch/elasticsearch-getting-start.html
索引和类型是必需的,而id部分是可选的。如果不指定ID,ElasticSearch会为我们生成一个ID。 但是,如果不指定id,应该使用HTTP的POST而不是PUT请求。原文出自【易百教程】,商业转载请联系作者获得授权,非商业请保留原文链接:https://www.yiibai.com/elasticsearch/elasticsearch-getting-start.html

索引名称是任意的。如果服务器上没有此名称的索引,则将使用默认配置来创建一个索引。
至于类型名称,它也是任意的。 它有几个用途,包括:每种类型都有自己的ID空间;不同类型具有不同的映射(“模式”,定义属性/字段应如何编制索引);搜索多种类型是可以的,并且也很常见,但很容易搜索一种或多种指定类型。

更新索引使用与之前完全相同的索引请求,更新后对象中的_version属性的值会发生变化,版本号(_version)可用于跟踪文档已编入索引的次数。它的主要目的是允许乐观的并发控制
版本号自动添加。

获取文档/索引
http://localhost:9200/<index>/<type>/<id> 就可以获取信息

_search端点
使用_search端点,可选择使用索引和类型。也就是说,按照以下模式向URL发出请求:<index>/<type>/_search。其中,index和type都是可选的。

指定搜索的字段
查询字符串查询有一些可以指定设置,如果不使用,它将会使用默认的设置值。
这样的设置称为“fields”,可用于指定要搜索的字段列表。如果不使用“fields”字段,ElasticSearch查询将默认自动生成的名为“_all”的特殊字段,来基于所有文档中的各个字段匹配搜索。原文出自【易百教程】,商业转载请联系作者获得授权,非商业请保留原文链接:https://www.yiibai.com/elasticsearch/elasticsearch-getting-start.html
curl -XPOST "http://localhost:9200/_search" -d'
{
    "query": {
        "query_string": {
            "query": "ford",
            "fields": ["title"]
        }
    }
}'

条件过滤器
curl -XPOST "http://localhost:9200/_search" -d'
{
    "query": {
        "filtered": {
            "query": {
                "query_string": {
                    "query": "drama"
                }
            },
            "filter": {
                "term": { "year": 1962 }
            }
        }
    }
}'
这个两个命中的数据的 year 字段的值都是等于 1962

无需查询即可进行过滤
curl -XPOST "http://localhost:9200/_search" -d'
{
    "query": {
        "filtered": {
            "query": {
                "match_all": {
                }
            },
            "filter": {
                "term": { "year": 1962 }
            }
        }
    }
}'


创建索引
POST http://localhost:9200/schools
响应:{"acknowledged": true}

创建映射和添加数据
POST http://localhost:9200/schools/_bulk
请求体
{
   "index":{
      "_index":"schools", "_type":"school", "_id":"1"
   }
}
{
   "name":"Central School", "description":"CBSE Affiliation", "street":"Nagan",
   "city":"paprola", "state":"HP", "zip":"176115", "location":[31.8955385, 76.8380405],
   "fees":2000, "tags":["Senior Secondary", "beautiful campus"], "rating":"3.5"
}
{
   "index":{
      "_index":"schools", "_type":"school", "_id":"2"
   }
}
{
   "name":"Saint Paul School", "description":"ICSE 
   Afiliation", "street":"Dawarka", "city":"Delhi", "state":"Delhi", "zip":"110075",
   "location":[28.5733056, 77.0122136], "fees":5000,
   "tags":["Good Faculty", "Great Sports"], "rating":"4.5"
}
{
   "index":{"_index":"schools", "_type":"school", "_id":"3"}
}
{
   "name":"Crescent School", "description":"State Board Affiliation", "street":"Tonk Road", 
   "city":"Jaipur", "state":"RJ", "zip":"176114","location":[26.8535922, 75.7923988],
   "fees":2500, "tags":["Well equipped labs"], "rating":"4.5"
}

响应结果
{
   "took":328, "errors":false,"items":[
      {
         "index":{
            "_index":"schools", "_type":"school", "_id":"1", "_version":1, "_shards":{
               "total":2, "successful":1, "failed":0
            }, "status":201
         }
      },

      {
         "index":{
            "_index":"schools", "_type":"school", "_id":"2", "_version":1, "_shards":{
               "total":2, "successful":1, "failed":0
            }, "status":201
         }
      },

      {
         "index":{
            "_index":"schools", "_type":"school", "_id":"3", "_version":1, "_shards":{
               "total":2, "successful":1, "failed":0
            }, "status":201
         }
      }
   ]
}


Elasticsearch提供了一个REST API,通过HTTP通过JSON访问。 Elasticsearch使用以下约定 
1.多索引
API中的大多数操作(主要是搜索和其他操作)用于一个或多个索引。 这有助于用户通过只执行一次查询来搜索多个位置或所有可用数据。 许多不同的符号用于在多个索引中执行操作。
逗号分隔符号
POST http://localhost:9200/index1,index2,index3/_search
请求体
{
   "query":{
      "query_string":{
         "query":"any_string"
      }
   }
}

响应:来自index1,index2,index3的JSON对象,其中包含any_string

2.所有索引的_all关键字
POST http://localhost:9200/_all/_search
请求体:
{
   "query":{
      "query_string":{
         "query":"any_string"
      }
   }
}
响应:来自所有索引的JSON对象,并且有any_string

3.通配符(*,+, - ) 
(其中+表示允许, - 表示不允许)
POST http://localhost:9200/school*/_search
来自所有索引的JSON对象,它们以“school”开头,但不是schools_gov

4.日期索引名称中的数学支持
http://localhost:9200/<accountdetail-{now-2d{YYYY.MM.dd|utc}}>/_search
其中:<accountdetail-{now-d}>   对应accountdetail-2016.12.29
<accountdetail-{now-M}>         对应accountdetail-2015.11.30
<accountdetail-{now{YYYY.MM}}>  对应accountdetail-2015.12

美化结果
可以通过附加一个网址查询参数(即pretty = true),获得格式正确的JSON对象的响应
POST http://localhost:9200/schools/_search?pretty = true


索引API
当使用特定映射对相应索引发出请求时,它有助于在索引中添加或更新JSON文档。 例如,以下请求将JSON对象添加到索引学校和学校映射下。
POST http://localhost:9200/schools/school/4
请求正文
{
   "name":"City School", "description":"ICSE", "street":"West End", "city":"Meerut", 
   "state":"UP", "zip":"250002", "location":[28.9926174, 77.692485], "fees":3500, 
   "tags":["fully computerized"], "rating":"4.5"
}
响应
{
   "_index":"schools", "_type":"school", "_id":"4", "_version":1,
   "_shards":{"total":2, "successful":1,"failed":0}, "created":true
}
当请求将JSON对象添加到特定索引时,如果该索引不存在,那么此API会自动创建该索引以及该特定JSON对象的基础映射。
可以通过将以下参数的值更改为false来禁用此功能,这个值是存在于elasticsearch.yml文件中,打开elasticsearch.yml文件设置如下
action.auto_create_index:false
index.mapper.dynamic:false

版本控制
POST http://localhost:9200/schools/school/1?version = 1
请求正文
{
   "name":"Central School", "description":"CBSE Affiliation", "street":"Nagan",
   "city":"paprola", "state":"HP", "zip":"176115", "location":[31.8955385, 76.8380405],
   "fees":2200, "tags":["Senior Secondary", "beautiful campus"], "rating":"3.3"
}
响应内容
{
   "_index":"schools", "_type":"school", "_id":"1", "_version":2,
   "_shards":{"total":2, "successful":1,"failed":0}, "created":false
}

操作类型
操作类型用于强制创建操作,这有助于避免覆盖现有文档
POST http://localhost:9200/tutorials/chapter/1?op_type = create
请求正文
{
   "Text":"this is chapter one"
}
响应内容
{
   "_index":"tutorials", "_type":"chapter", "_id":"1", "_version":1,
   "_shards":{"total":2, "successful":1, "failed":0}, "created":true
}


自动生成ID
当在索引操作中未指定ID时,Elasticsearch自动为文档生成ID

获取API
GET http://localhost:9200/schools/school/1
响应
{
   "_index":"schools", "_type":"school", "_id":"1", "_version":2,
   "found":true, "_source":{
      "name":"Central School", "description":"CBSE Affiliation", 
      "street":"Nagan", "city":"paprola", "state":"HP", "zip":"176115",
      "location":[31.8955385,76.8380405], "fees":2200, 
      "tags":["Senior Secondary", "beautiful campus"], "rating":"3.3"
   }
}

删除API
通过向Elasticsearch发送HTTP DELETE请求来删除指定的索引,映射或文档
DELETE http://localhost:9200/schools/school/4
响应
{
   "found":true, "_index":"schools", "_type":"school", "_id":"4", "_version":2,
   "_shards":{"total":2, "successful":1, "failed":0}
}


更新API
脚本用于执行此操作,版本控制用于确保在获取和重建索引期间没有发生更新
POST http://localhost:9200/schools_gov/school/1/_update
请求正文
{
   "script":{
      "inline": "ctx._source.fees+ = inc", "params":{
         "inc": 500
      }
   }
}
响应结果
{
   "_index":"schools_gov", "_type":"school", "_id":"1", "_version":2,
   "_shards":{"total":2, "successful":1, "failed":0}
}

多获取API
POST http://localhost:9200/_mget
请求正文
{
   "docs":[
      {
         "_index": "schools", "_type": "school", "_id": "1"
      },

      {
         "_index":"schools_gev", "_type":"school", "_id": "2"
      }
   ]
}
响应结果
{
   "docs":[
      {
         "_index":"schools", "_type":"school", "_id":"1",
         "_version":1, "found":true, "_source":{
            "name":"Central School", "description":"CBSE Afiliation",
            "street":"Nagan", "city":"paprola", "state":"HP", "zip":"176115",
            "location":[31.8955385,76.8380405], "fees":2000, 
            "tags":["Senior Secondary", "beatiful campus"], "rating":"3.5"
         }
      },

      {
         "_index":"schools_gev", "_type":"school", "_id":"2", "error":{

            "root_cause":[{
               "type":"index_not_found_exception", "reason":"no such index", 
               "index":"schools_gev"
            }],

            "type":"index_not_found_exception", "reason":"no such index", 
            "index":"schools_gev"
         }
      }
   ]
}

多索引
Elasticsearch允许我们搜索存在于所有索引或一些特定索引中的文档。 例如,如果我们需要搜索名称包含central的所有文档。
GET http://localhost:9200/_search?q = name:central
响应
{
   "took":78, "timed_out":false, "_shards":{"total":10, "successful":10, "failed":0},
   "hits":{
      "total":1, "max_score":0.19178301, "hits":[{
         "_index":"schools", "_type":"school", "_id":"1", "_score":0.19178301,
         "_source":{
            "name":"Central School", "description":"CBSE Affiliation", 
            "street":"Nagan", "city":"paprola", "state":"HP", "zip":"176115",
            "location":[31.8955385, 76.8380405], "fees":2000, 
            "tags":["Senior Secondary", "beautiful campus"], "rating":"3.5"
         }
      }]
   }
}

多类型
还可以在所有类型或某种指定类型的索引中搜索所有文档。
Get http://localhost:9200/schools/_search?q = tags:sports
响应
{
   "took":16, "timed_out":false, "_shards":{"total":5, "successful":5, "failed":0},
   "hits":{
      "total":1, "max_score":0.5, "hits":[{
         "_index":"schools", "_type":"school", "_id":"2", "_score":0.5,
         "_source":{
            "name":"Saint Paul School", "description":"ICSE Afiliation", 
            "street":"Dawarka", "city":"Delhi", "state":"Delhi", "zip":"110075", 
            "location":[28.5733056, 77.0122136], "fees":5000, 
            "tags":["Good Faculty", "Great Sports"], "rating":"4.5"
         }
      }]
   }
}


删除索引
DELETE http://localhost:9200/colleges
可以通过使用_all,*删除所有索引。


在Elasticsearch中,通过使用基于JSON的查询进行搜索。 查询由两个子句组成
1.叶查询子句 - 这些子句是匹配,项或范围的,它们在特定字段中查找特定值;
2.复合查询子句 - 这些查询是叶查询子句和其他复合查询的组合,用于提取所需的信息

匹配所有查询
POST http://localhost:9200/schools*/_search
请求正文
{
   "query":{
      "match_all":{}
   }
}
响应
{
   "took":1, "timed_out":false, "_shards":{"total":10, "successful":10, "failed":0},
   "hits":{
      "total":5, "max_score":1.0, "hits":[
         {
            "_index":"schools", "_type":"school", "_id":"2", "_score":1.0,
            "_source":{
               "name":"Saint Paul School", "description":"ICSE Affiliation",
               "street":"Dawarka", "city":"Delhi", "state":"Delhi", 
               "zip":"110075", "location":[28.5733056, 77.0122136], "fees":5000, 
               "tags":["Good Faculty", "Great Sports"], "rating":"4.5"
            }
         },

         {
            "_index":"schools_gov", "_type":"school", "_id":"2", "_score":1.0,
            "_source":{
               "name":"Government School", "description":"State Board Affiliation",
               "street":"Hinjewadi", "city":"Pune", "state":"MH", "zip":"411057",
               "location":[18.599752, 73.6821995], "fees":500, "tags":["Great Sports"],
               "rating":"4"
            }
         },

         {
            "_index":"schools", "_type":"school", "_id":"1", "_score":1.0,
            "_source":{
               "name":"Central School", "description":"CBSE Affiliation",
               "street":"Nagan", "city":"paprola", "state":"HP", 
               "zip":"176115", "location":[31.8955385, 76.8380405], 
               "fees":2200, "tags":["Senior Secondary", "beautiful campus"], 
               "rating":"3.3"
            }
         },

         {
            "_index":"schools_gov", "_type":"school", "_id":"1", "_score":1.0,
            "_source":{
               "name":"Model School", "description":"CBSE Affiliation",
               "street":"silk city", "city":"Hyderabad", "state":"AP", 
               "zip":"500030", "location":[17.3903703, 78.4752129], "fees":700, 
               "tags":["Senior Secondary", "beautiful campus"], "rating":"3"
            }
         },

         {
            "_index":"schools", "_type":"school", "_id":"3", "_score":1.0,
            "_source":{
               "name":"Crescent School", "description":"State Board Affiliation",
               "street":"Tonk Road", "city":"Jaipur", "state":"RJ", "zip":"176114",
               "location":[26.8535922, 75.7923988], "fees":2500, 
               "tags":["Well equipped labs"], "rating":"4.5"
            }
         }
      ]
   }
}


匹配查询
此查询将文本或短语与一个或多个字段的值匹配。
POST http://localhost:9200/schools*/_search
请求正文
{
   "query":{
      "match" : {
         "city":"pune"
      }
   }
}
响应
{
   "took":1, "timed_out":false, "_shards":{"total":10, "successful":10, "failed":0},
   "hits":{
      "total":1, "max_score":0.30685282, "hits":[{
         "_index":"schools_gov", "_type":"school", "_id":"2", "_score":0.30685282, 
         "_source":{
            "name":"Government School", "description":"State Board Afiliation",
            "street":"Hinjewadi", "city":"Pune", "state":"MH", "zip":"411057",
            "location":[18.599752, 73.6821995], "fees":500, 
            "tags":["Great Sports"], "rating":"4"
         }
      }]
   }
}

multi_match查询
此查询将文本或短语与多个字段匹配
POST http://localhost:9200/schools*/_search
请求正文
{
   "query":{
      "multi_match" : {
         "query": "hyderabad",
         "fields": [ "city", "state" ]
      }
   }
}
响应
{
   "took":16, "timed_out":false, "_shards":{"total":10, "successful":10, "failed":0},
   "hits":{
      "total":1, "max_score":0.09415865, "hits":[{
         "_index":"schools_gov", "_type":"school", "_id":"1", "_score":0.09415865,
         "_source":{
            "name":"Model School", " description":"CBSE Affiliation", 
            "street":"silk city", "city":"Hyderabad", "state":"AP", 
            "zip":"500030", "location":[17.3903703, 78.4752129], "fees":700, 
            "tags":["Senior Secondary", "beautiful campus"], "rating":"3"
         }
      }]
   }
}

查询字符串查询
此查询使用查询解析器和query_string关键字
POST http://localhost:9200/schools/_search
请求正文
{
   "query":{
      "query_string":{
         "query":"good faculty"
      }
   }
}
响应
{
   "took":16, "timed_out":false, "_shards":{"total":10, "successful":10, "failed":0}, 
   "hits":{
      "total":1, "max_score":0.09492774, "hits":[{
         "_index":"schools", "_type":"school", "_id":"2", "_score":0.09492774, 
         "_source":{
            "name":"Saint Paul School", "description":"ICSE Affiliation",
            "street":"Dawarka", "city":"Delhi", "state":"Delhi",
            "zip":"110075", "location":[28.5733056, 77.0122136],
            "fees":5000, "tags":["Good Faculty", "Great Sports"],
            "rating":"4.5" 
         }
      }]
   }
}

期限等级查询
处理结构化数据,如数字,日期和枚举
POST http://localhost:9200/schools/_search
请求正文
{
   "query":{
      "term":{"zip":"176115"}
   }
}
响应
{
   "took":1, "timed_out":false, "_shards":{"total":10, "successful":10, "failed":0},
   "hits":{
      "total":1, "max_score":0.30685282, "hits":[{
         "_index":"schools", "_type":"school", "_id":"1", "_score":0.30685282,
         "_source":{
            "name":"Central School", "description":"CBSE Affiliation",
            "street":"Nagan", "city":"paprola", "state":"HP", "zip":"176115",
            "location":[31.8955385, 76.8380405], "fees":2200, 
            "tags":["Senior Secondary", "beautiful campus"], "rating":"3.3"
         }
      }]
   }
}

范围查询
此查询用于查找值的范围之间的值的对象。 为此,需要使用类似
gte − 大于和等于  gt − 大于  lte − 小于和等于  lt − 小于
POST http://localhost:9200/schools*/_search
请求正文
{
   "query":{
      "range":{
         "rating":{
            "gte":3.5
         }
      }
   }
}
响应
{
   "took":31, "timed_out":false, "_shards":{"total":10, "successful":10, "failed":0},
   "hits":{
      "total":3, "max_score":1.0, "hits":[
         {
            "_index":"schools", "_type":"school", "_id":"2", "_score":1.0,
            "_source":{
               "name":"Saint Paul School", "description":"ICSE Affiliation",
               "street":"Dawarka", "city":"Delhi", "state":"Delhi", 
               "zip":"110075", "location":[28.5733056, 77.0122136], "fees":5000, 
               "tags":["Good Faculty", "Great Sports"], "rating":"4.5"
            }
         }, 

         {
            "_index":"schools_gov", "_type":"school", "_id":"2", "_score":1.0, 
            "_source":{
               "name":"Government School", "description":"State Board Affiliation",
               "street":"Hinjewadi", "city":"Pune", "state":"MH", "zip":"411057",
               "location":[18.599752, 73.6821995] "fees":500, 
               "tags":["Great Sports"], "rating":"4"
            }
         },

         {
            "_index":"schools", "_type":"school", "_id":"3", "_score":1.0,
            "_source":{
               "name":"Crescent School", "description":"State Board Affiliation",
               "street":"Tonk Road", "city":"Jaipur", "state":"RJ", "zip":"176114", 
               "location":[26.8535922, 75.7923988], "fees":2500,
               "tags":["Well equipped labs"], "rating":"4.5"
            }
         }
      ]
   }
}

复合查询
这些查询是通过使用如和,或,非和或等,用于不同索引或具有函数调用等的布尔运算符彼此合并的不同查询的集合
POST http://localhost:9200/schools*/_search
请求正文
{
   "query":{
      "filtered":{
         "query":{
            "match":{
               "state":"UP"
            }
         },

         "filter":{
            "range":{
               "rating":{
                  "gte":4.0
               }
            }
         }
      }
   }
}
响应
{
   "took":16, "timed_out":false, "_shards":{"total":10, "successful":10, "failed":0},
   "hits":{"total":0, "max_score":null, "hits":[]}
}

连接查询
用于检索在查询中匹配的文档的子文档或父文档
POST http://localhost:9200/tutorials/_search
请求正文
{
   "query":
   {
      "has_child" : {
         "type" : "article", "query" : {
            "match" : {
               "Text" : "This is article 1 of chapter 1"
            }
         }
      }
   }
}
响应
{
   "took":21, "timed_out":false, "_shards":{"total":5, "successful":5, "failed":0},
   "hits":{
      "total":1, "max_score":1.0, "hits":[{
         "_index":"tutorials", "_type":"chapter", "_id":"1", "_score":1.0,
         "_source":{
            "Text":"this is chapter one"
         }
      }]
   }
}

地理查询
这些查询处理地理位置和地理点。这些查询有助于查找任何位置附近的学校或任何其他地理对象。需要使用地理位置数据类型
POST http://localhost:9200/schools*/_search
请求正文

    {
       "query":{
          "filtered":{
             "filter":{
                "geo_distance":{
                   "distance":"100km",
                   "location":[32.052098, 76.649294]
                }
             }
          }
       }
    }

响应

    {
       "took":6, "timed_out":false, "_shards":{"total":10, "successful":10, "failed":0},
       "hits":{
          "total":2, "max_score":1.0, "hits":[
             {
                "_index":"schools", "_type":"school", "_id":"2", "_score":1.0,
                "_source":{
                   "name":"Saint Paul School", "description":"ICSE Affiliation",
                   "street":"Dawarka", "city":"Delhi", "state":"Delhi", "zip":"110075",
                   "location":[28.5733056, 77.0122136], "fees":5000,
                   "tags":["Good Faculty", "Great Sports"], "rating":"4.5"
                }
             },
    
             {
                "_index":"schools", "_type":"school", "_id":"1", "_score":1.0,
                "_source":{
                   "name":"Central School", "description":"CBSE Affiliation",
                   "street":"Nagan", "city":"paprola", "state":"HP", "zip":"176115",
                   "location":[31.8955385, 76.8380405], "fees":2000,
                   "tags":["Senior Secondary", "beautiful campus"], "rating":"3.5"
                }
             }
          ]
       }
    }

ES将数据存储于一个或多个索引中,索引是具有类似特性的文档的集合。类比传统的关系型数据库领域来说,索引相当于SQL中的一个数据库,或者一个数据存储方案(schema)。


java关联elasticsearch的api使用
QueryBuilders.termsQuery(String fieldName, String...value);查询一个字段的一个或多个对应的值
QueryBuilders.queryStringQuery(req.getCpCharge().toString()).field("isPurchase")查询某个字段的值,左右模糊
QueryBuilders.termQuery("convergeStatus", req.getConverge().toString())精确匹配字段
QueryBuilders.rangeQuery("albumCreateTime").gt(req.getGitvCreateStart()).lt(req.getGitvCreateEnd());范围查询
QueryBuilders.rangeQuery("duration").from(req.getPalyTimeLow()).to(req.getPalyTimeHigh());区间查询

elasticsearch-head插件安装
进入elasticsearch2.3.0/bin目录下,打开cmd,输入
plugin install mobz/elasticsearch-head
安装成功后,启动elasticsearch,输入网址http://localhost:9200/_plugin/head/
进入到elasticsearch的管理页面

logstash使用
使用前先启动elasticsearch及安装elasticsearch-head
下载解压后,进入logstash2.3/bin目录,创建文件logstash.conf,编辑输入
input {
stdin {
}
}

output {
elasticsearch {hosts => “127.0.0.1:9200” } #elasticsearch服务地址
stdout{
}
}

logstash -f logstash.conf启动
-f:指定logstash的配置文件
-e:格式是后面跟字符串,这个字符串就被当做是logstash的配置;如果"",那么默认使用stdin作为输出,stdout作为输出;
-t:测试配置文件是否正确
,启动后输入hello world,进入localhost:9200/_plugin/head可以查看到输入的数据hello world

http://localhost:9200/student/converge/_count/ GET
查询类型下数据的数量

删除类型下的所有数据
http://localhost:9200/student/cs/_delete_by_query?conflicts=proceed/ POST
{“query”:{“match_all”:{}}}

设置最大查询深度
http://localhost:9200/student/_settings/ put
{ “index” : { “max_result_window” : 100000}}

分页查询
http://localhost:9200/student/cs/_search/ get
{
“query”:{
“match”:{“partnerCode”:“GITV”,“albumId”:1191193}
},
“from”:0,
“size”:10
}

查询索引下所有类型
$ curl -XGET 'http://localhost:9200/twitter/_search
查询索引下指定类型
$ curl -XGET 'http://localhost:9200/twitter/tweet,user/_search
查询多个索引下的指定类型
$ curl -XGET 'http://localhost:9200/kimchy,elasticsearch/tweet/_search
查询所有索引所有类型
$ curl -XGET 'http://localhost:9200/_search

发布了45 篇原创文章 · 获赞 9 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/zhanglinlove/article/details/99683303