關係數據搜索缺點java
config/elasticsearch.yml文件配置,解決跨域問題git
elasticsearchgithub
elasticsearch-headsql
配置master數據庫
cluster.name: jim node.name: master node.master: true network.host: 127.0.0.1 # 端口保持默認
配置slavenpm
cluster.name: jim-slave node.name: slave1 network.host: 127.0.0.1 http.port: 8200 # 避免和master端口衝突 discovery.zen.ping.unicast.hosts: ["127.0.0.1"] # 查找master
索引:含有相同屬性的文檔集合【sql中數據庫】後端
類型:索引能夠定義一個或多個類型,文檔必須屬於一個類型【sql中表】跨域
PUT lagou { "setting":{ "index":{ "number_of_shards":5, # 切片數 "number_of_replicas":1 # 副本數,可修改 } } } # 獲取設置 GET lagou/_settings GET _all/_settings GET _settings GET lagou1,lagou2/_settings #更新配置 PUT lagou/_settings { "number_of_replicas":2 } #獲取索引 GET lagou GET _all #添加數據 POST lagou/job/1 { "key":"value", ... } #獲取數據 GET lagou/job/1 #指定id存儲 GET lagou/job/ #自動生成一個uuid看成id GET lagou/job/1?_source=key1,key2 #修改數據 PUT lagou/job/1 { "key":"value", ... } POST lagou/job/1/_update { "doc":{ "key":"value", ... } } # 腳本形式修改數據 POST lagou/job/1/_update { "script":{ "lang":"painless", "inline":"ctx._source.key = value", # 這裏的value就能夠使用params.key "params":{ "key":value } } } #刪除數據 DELETE lagou/job/1 DELETE lagou
GET lagou/job/_mget { "docs":{ 條件 } } GET lagou/job/1/_mget { "ids":[id1,id2...] }
POST _bulk {"index":{"_index":"lagou","_type":"job","_id":"1"}} {"title":"批量操做嘍","city":"北京"} {"delete":{"_index":"lagou","_type":"job","_id":"1"}} {"create":{"_index":"lagou","_type":"job","_id":"1"}} {"update":{"_index":"lagou","_type":"job","_id":"1"}}
PUT lagou { "mappings":{ "type_name":{ "dynamic":false, # 索引固定 "properties":{ "name":{ "store":true,(是否保存) "type":屬性,(即字段類型) "index":"analyzer" #使用分詞 "analyzer":"ik_max_word"(分析器,即分詞類型) }, "age":{ "store":true, "type":屬性(若是是keywork則不會被分詞) }, "date":{ "store":true, "type":date, "format":"yy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis" } ... } } } }
# 經過id查詢 GET lagou/job/id # 條件查詢 GET lagou/job/_search # 能夠使用post和get兩種方式,建議使用post { "stored_fields":[字段1,字段2...], # 指定返回的字段 "query":{ "match":{ # "match_all":{}所有查詢 match_phrase:{}徹底匹配查詢 "字段":內容 ... } }, "from":1 "size":1 "sort":[ {"字段":{ "order":"desc" } } ] }
GET lagou/_search { "類型":{ "分組名":{ "term":{ # stat min均可以使用 "字段":內容 ... } } } }
GET lagou/job/_search { "query":{ "term":{ "字段":內容 ... } } }
GET lagou/job/_search { "query":{ "terms":{ "字段":[內容1,...] ... } } }
GET lagou/job/_search { "query":{ "multi_match":{ "query":內容, "fields":[字段1^3,字段2...] # ^3表示權重 } } }
GET lagou/job/_search { "query":{ "query_string":{ "query":"condition AND|OR condition", "fields":[字段1^3,字段2...] # ^3表示權重 } } }
GET lagou/job/_search { "query":{ "range":{ "字段":{ "gte":10, "lte":20, "boost":2.0 # 權重 } } } }
GET lagou/job/_search { "query":{ "bool":{ "filter":{ # 過濾字段 "查詢方式":{ # "term"|"match"等 "字段":內容 } }, "must":[], # 條件必須所有知足 "should":[], # 條件知足其一 "must_not":[] # 必須一個不知足 } } }
GET _analyze { "analyzer":"ik_max_word", # 與ik_smart區別:ik_smart以最小詞量分詞,如工程師就不會再進行工程/師分詞 "text":"內容" }
文檔精選:bash