ElasticSearch學習筆記

        Elasticsearch 是一個建立在全文搜索引擎 Apache Lucene(TM) 基礎上的搜索引擎,可以說 Lucene 是當今最先進,最高效的全功能開源搜索引擎框架。

基礎概念理解:

 

  • 索引(Index)                --     數據庫
  • 類型(Type)                 --     表
  • 文檔(document)        --        記錄
  • 字段(Field)                --        列屬性

 

ElasticSearch安裝與啓動:

  

 雙擊elasticsearch啓動後,使用elasticsearch head 進入http://127.0.0.1:9200

#EsInfo 
#GET
http://localhost:9200/
#Es insert index
#PUT
http://localhost:9200/megacorp/employee/5

{
    "first_name" :  "Jim",
    "last_name" :   "Smith",
    "age" :         36,
    "about" :       "I like to collect rock albums",
    "interests":  [ "music" ]
}
#Es getDocById 
#GET
http://localhost:9200/megacorp/employee/3
#ES getAllDocs
#GET
http://localhost:9200/megacorp/employee/_search
#getDocsByQueryConditons
#GET
http://localhost:9200/megacorp/employee/_search?q=last_name:xiang
#Es getDocsByDSL  
#GET
http://localhost:9200/megacorp/employee/_search

{
    "query" : {
        "match" : {
			"last_name" : "xiang"
        }
    }
}
#Es getDocsByDSLAndFIiter
#GET
http://localhost:9200/megacorp/employee/_search

{
    "query" : {
        "bool" : {
            "filter" : {
                "range" : {
                    "age" : { "gt" : 30 } 
                }
            },
            "must" : {
                "match" : {
                    "last_name" : "smith" 
                }
            }
        }
    }
}
#Es getDocsByDSLMatchPhrase
#GET
http://localhost:9200/megacorp/employee/_search

{
    "query" : {
        "match_phrase" : {
			"about" : "rock climbing"
        }
    }
}
#Es getDocsByDSLHighLight
#GET
http://localhost:9200/megacorp/employee/_search

{
    "query" : {
        "match_phrase" : {
            "about" : "rock climbing"
        }
    },
    "highlight": {
        "fields" : {
            "about" : {}
        }
    }
}
#Es aggregations
#GET
http://localhost:9200/megacorp/employee/_search

{
  "aggs": {
    "all_interests": {
      "terms": { "field": "interest" }
    }
  }
}
#Es getHealth
#GET
http://localhost:9200/_cluster/health
#Es shards_setting
#PUT
http://localhost:9200/blog

{
   "settings" : {
      "number_of_shards" : 3,
      "number_of_replicas" : 2
   }
}

 

 

 

 

 

 

 

 

 

 

 

發佈了25 篇原創文章 · 獲贊 20 · 訪問量 6523
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章