(图片来源网络,侵删)
1. GET /mymayikt/user/_search 查询所有GET /index/type/id2.查询指定字段GET bizseer-ccbdoap-task_result-202106/_search GET /_search { "query": { "match": { "tweet": "elasticsearch" } } }多条件查询 { "bool": { "must": { "match": { "tweet": "elasticsearch" }}, "must_not": { "match": { "name": "mary" }}, "should": { "match": { "tweet": "full text" }}, "filter": { "range": { "age" : { "gt" : 30 }} } } }2.插入POST _bulk{"index":{"_index":"bizseer-ccbdoap-task_result-202106","_type":"_doc"}}{"exceptionLevel":2}分页查询:GET bizseer-ccbdoap-task_result-202106/_search{ "from" : 0 , "size" : 1, "query" : { "match_all" : { } }}es的插入语句必须是单行上:POST _bulk{"index":{"_index":"bizseer-ccbdoap-task_result-202106","_type":"_doc"}}{"exceptionLevel":2}批量删除数据POST bizseer-ccbdoap-task_result-202106/_delete_by_query?pretty{ "query": { "term": { "ap": "1003" } }}es应该用固定结构,动态mapping需要.keywordPUT jh-es-test索引存在的mapping设置:POST jh-es-test/_doc/_mapping{"_doc":{"dynamic":false,"_all":{"enabled":false},"properties":{"@timestamp":{"type":"date"},"APP_DU":{"type":"keyword"},"ap":{"type":"keyword"},"comp_code":{"type":"keyword"},"subsysname":{"type":"keyword"},"检查类别":{"type":"keyword"},"检查类型":{"type":"keyword"},"检查结果":{"type":"keyword"},"检查结果明细":{"type":"keyword"},"检查项":{"type":"keyword"}}}}基本查询{"query":{"match":{"name":"啦啦啦啦"}},"sort":[{"id":"desc"}]}es多条件查询{"query":{"bool":{"must":[{"term":{"title":"java"}},{"term":{"title":"elasticsearch"}}]}}}es对id的查询,模糊索引GET ccb-/_search{"query":{"bool":{"must":[{"term":{"_id":"123"}}]}}}POST jh-es-test/_doc/_mapping{ "_doc": { "dynamic": "false", "_all": { "enabled": false }, "properties": { "@timestamp": { "type": "date" }, "APP_DU": { "type": "keyword" }, "ap": { "type": "keyword" }, "comp_code": { "type": "keyword" }, "subsysname": { "type": "keyword" }, "检查类别": { "type": "keyword" }, "检查类型": { "type": "keyword" }, "检查结果": { "type": "keyword" }, "检查结果明细": { "type": "keyword" }, "检查项": { "type": "keyword" } } } }es范围查询:GET /megacorp/employee/_search { "query" : { "bool": { "must": { "match" : { "last_name" : "smith" } }, "filter": { "range" : { "age" : { "gt" : 30 } } } } } } es聚合:all_interests为别名 GET /megacorp/employee/_search { "aggs": { "all_interests": { "terms": { "field": "interests" } } } }es只查询文档的指定字段内容 GET /website/blog/123?_source=title,text多个索引的搜索:/g,u/_search在任何以 g 或者 u 开头的索引中搜索所有的类型/_all/user,tweet/_search在所有的索引中搜索 user 和 tweet 类型multi_match 查询可以在多个字段上执行相同的 match 查询: { "multi_match": { "query": "full text search", "fields": [ "title", "body" ] } }term 查询被用于精确值匹配,这些精确值可能是数字、时间、布尔或者那些not_analyzed 的字符串terms是多值查询,只要满足某个即为符合条件; { "terms": { "tag": [ "search", "full_text", "nosql" ] }}exists 查询和 missing 查询被用于查找那些指定字段中有值 (exists) 或无值 (missing) 的文档相当于数据库的null和not null { "exists": { "field": "title" } }高级查询里,must为精准匹配,must_not为不匹配;should为提高_score(评分),如果有精准匹配,则该搜索不生效;filter为快速的过滤数据;filter里也可以多条件查询,为bool方式{ "bool": { "must": { "match": { "title": "how to make millions" }}, "must_not": { "match": { "tag": "spam" }}, "should": [ { "match": { "tag": "starred" }} ], "filter": { "bool": { "must": [ { "range": { "date": { "gte": "2014-01-01" }}}, { "range": { "price": { "lte": 29.99 }}} ], "must_not": [ { "term": { "category": "ebooks" }} ] } } } }校验查询的正确性:GET /gb/tweet/_validate/query?explain { "query": { "tweet" : { "match" : "really powerful" } }es默认排序是按照得分降序排列的; GET /_search { "query" : { "bool" : { "filter" : { "term" : { "user_id" : 1 }} } }, "sort": { "date": { "order": "desc" }} }如果不指定类型,ElasticSearch字符串将默认被同时映射成text和keyword类型;es的一个字段可以设置多个类型,也可以通过多字段设置不同解析器
0 评论