mappings
PUT twitter { "settings" : { "index" : { "number_of_shards" : 3, "number_of_replicas" : 2 } }, "mappings" : { "_doc" : { "properties" : { "field1" : { "type" : "text" } } } } } 查看索引 GET /twitter/ GET /twitter/_search 删除索引 DELETE /twitter 映射管理 Core Datatypes 核心类型 string text and keyword Numeric datatypes long, integer, short, byte, double, float, half_float, scaled_float Date datatype date Boolean datatype boolean Binary datatype binary Range datatypes 范围 integer_range, float_range, long_range, double_range, date_range Complex datatypes 复合类型 Array datatype 数组就是多值,不需要专门的类型 Object datatype object :表示值为一个JSON 对象 Nested datatype nested:for arrays of JSON objects(表示值为JSON对象数组 ) Geo datatypes 地理数据类型 Geo-point datatype geo_point: for lat/lon points (经纬坐标点) Geo-Shape datatype geo_shape: for complex shapes like polygons (形状表示) Specialised datatypes 特别的类型 IP datatype ip: for IPv4 and IPv6 addresses Completion datatype completion: to provide auto-complete suggestions Token count datatype token_count: to count the number of tokens in a string mapper-murmur3 murmur3: to compute hashes of values at index-time and store them in the index Percolator type Accepts queries from the query-dsl join datatype Defines parent/child relation for documents within the same index 文档管理 新建 指定id PUT twitter/_doc/1 { "id": 1, "user" : "kimchy", "post_date" : "2009-11-15T14:12:12", "message" : "trying out Elasticsearch" } 自动生成id POST twitter/_doc/ { "id": 1, "user" : "kimchy", "post_date" : "2009-11-15T14:12:12", "message" : "trying out Elasticsearch" } 查看 HEAD twitter/_doc/11 GET twitter/_doc/1 更新 PUT twitter/_doc/1 { "id": 1, "user" : "kimchy", "post_date" : "2009-11-15T14:12:12", "message" : "trying out Elasticsearch" } 删除 DELETE twitter/_doc/1 批处理 POST _bulk { "index" : { "_index" : "test", "_type" : "_doc", "_id" : "1" } } { "field1" : "value1" } { "delete" : { "_index" : "test", "_type" : "_doc", "_id" : "2" } } { "create" : { "_index" : "test", "_type" : "_doc", "_id" : "3" } } { "field1" : "value3" } { "update" : {"_id" : "1", "_type" : "_doc", "_index" : "test"} } { "doc" : {"field2" : "value2"} } index 无论是否存在,都会成功 create 存在会提示 update 不存在会提示 delete 不存在会提示 结构化搜索 精确值查找term POST /my_store/_doc/_bulk { "index": { "_id": 1 }} { "price" : 10, "productID" : "XHDK-A-1293-#fJ3" } { "index": { "_id": 2 }} { "price" : 20, "productID" : "KDKE-B-9947-#kL5" } { "index": { "_id": 3 }} { "price" : 30, "productID" : "JODL-X-1937-#pV7" } { "index": { "_id": 4 }} { "price" : 30, "productID" : "QQPX-R-3956-#aD8" }一个字段查询
GET my_store/_doc/_search { "query": { "term": { "price": "30" } } } 组合过滤 GET my_store/_doc/_search { "query": { "bool": { "should": [ { "term": { "price": 20 } }, { "term": { "productID": "XHDK-A-1293-#fJ3" } } ], "must_not": { "term": { "price": 30 } } } } } PUT my_store { "mappings" : { "_doc" : { "properties" : { "productID" : { "type" : "keyword" } } } } } GET /my_store/_analyze { "field": "productID", "text": "XHDK-A-1293-#fJ3" } 高亮 GET my_store/_doc/_search { "query": { "match": { "productID": "b" } }, "highlight": { "pre_tags" : ["<span>"], "post_tags" : ["</span>"], "title": {}, "content": {} } } } 全文搜索 POST /my_index/my_type/_bulk { "index": { "_id": 1 }} { "title": "The quick brown fox" } { "index": { "_id": 2 }} { "title": "The quick brown fox jumps over the lazy dog" } { "index": { "_id": 3 }} { "title": "The quick brown fox jumps over the quick dog" } { "index": { "_id": 4 }} { "title": "Brown fox brown dog" } 匹配查询 GET /my_index/my_type/_search { "query": { "match": { "title": "QUICK!" } } } GET /my_index/_analyze { "field": "title", "text": "QUICK!" } 组合查询 GET /my_index/my_type/_search { "query": { "bool": { "must": { "match": { "title": "quick" }}, "must_not": { "match": { "title": "lazy" }}, "should": [ { "match": { "title": "brown" }}, { "match": { "title": "dog" }} ] } } } 分词