PUT /my_index_name { "settings": { "number_of_replicas": 1, "number_of_shards": 3, "analysis": {}, "refresh_interval": "1s" }, "mappings": { "my_type_name": { //type名字 "properties": { //type的字段屬性 "title": { "type": "text", "analyzer": "ik_max_word" }, "name":{ "type": "text", "analyzer": "ik_max_word" }, "num":{ "type": "integer" } } } } }
也能夠單首創建setting和mappinghtml
字段屬性建立好之後,若是要修改設置的某個字段的屬性是修改不了的,能夠java
添加數據web
POST my_index_name/my_type_name { "title":"測試title", "name":"測試", "num":1 }
修改數據windows
POST my_index_name/my_type_name/AWZ8KV5GLlhkZVrwqqUS { "title":"測試title", "name":"測試111", "num":1 }
刪除索引 瀏覽器
不能刪除某個類型服務器
DELETE my_index_name
GET _search { "query": { "match": { "FIELD": "TEXT" } } }
GET /_search { "query": { "bool": { //組合查詢,各個子句之間的邏輯關係是與(and) "must": [ 必須知足的條件 { "match": { //普通匹配查詢 "username": "smith" } } ], "must_not": [ //必須不知足某條件 { "match_phrase": { //短語匹配查詢 "username": "granny smith" } } ], "filter": [ //過濾器 文檔必須匹配該過濾條件,跟must子句的惟一區別是,filter不影響查詢的score; { "exists": { //存在 "field": "title" } } ] } }, "aggs": { //聚合 "my_agg": { //聚合名 "terms": { "field": "user", "size": 10 } } }, "highlight": { //高亮 "pre_tags": [ "<em>" ], "post_tags": [ "</em>" ], "fields": { "body": { "number_of_fragments": 1, "fragment_size": 20 }, "title": {} } }, "size": 20, //一次查詢的數據量 "from": 100, //從第幾條數據開始 "_source": [ //要查詢的字段 "title", "id" ], "sort": [ //排序 { "_id": { "order": "desc" } } ] }
多字段查詢app
"multi_match": { "query": "Elastic", //匹配的字 "fields": ["user.*", "title^3"], //須要匹配的字段 "type": "best_fields" //查詢在內部執行的方式 best_fields(默認)查找與任何字段匹配的文檔 }multi_match
組合查詢elasticsearch
"bool": { "must": [], "must_not": [], "filter": [], "should": [], "minimum_should_match" : 1 //最小匹配度 }
範圍搜索分佈式
"range": { "age": { "gte": 10, "lte": 20, "boost": 2 } }