GET opt_log/_mapping
GET opt_log/_search
{
"query": {
"match_all": {}
}
}
GET opt_log/_search
{
"query": {
"match": {
"userCode": "888888"
}
}
}
GET login_log/_search
{
"query": {
"match_all": {}
},
"sort": [
{
"loginTime": {
"order": "desc"
}
}
]
}
GET opt_log_aaa/_search
{
"query": {
"match": {
"systemCode": "xxx"
}
},"sort": [
{
"createTime": {
"order": "desc"
}
}
]
}
多字段查询:
GET opt_log_aaa/_search
{
"query": {
"bool":{
"must": [
{"match": {
"systemCode": "xxx"
}},
{
"match": {
"baseTableCode": "xxx"
}
},{
"match": {
"moduleCode": "xxx"
}
}
]
}
},
"sort": [
{
"createTime": {
"order": "desc"
}
}
]
}
PUT操作
向elasticsearch插入引索或文档
//插入一个文档,字段自动识别类型
PUT /test1/type1/5
{
"name":"java前端",
"age":11,
"desc":"666"
}
//新增一个引索,字段类型手动定义
PUT /test2
{
"mappings": {
"properties": {
"name":{
"type": "text"
},
"age":{
"type": "long"
},
"birthday":{
"type": "date"
}
}
}
}
GET操作
GET /test1/type1/_search
{
"query":{
"match": {
"name": "张三" //查询匹配张三的文档
}
},
"_source":["name","age"], //查询结果只展示name和age
"sort":{
"age":{
"order":"asc" //age升序序排列
}
},
"from":0, //从0开始分页,每页大小为1
"size":1
}
GET /test1/type1/_search
{
"query":{
"bool": {
"must": [
{
"match": {
"name": "张三" //查询匹配张三的文档
}
}, //(多条件查询)
{
"match": {
"age": 12 //和年龄是12的张三
}
}
]
}
}
}
GET /test1/type1/_search
{
"query":{
"bool": {
"should": [
{
"match": {
"name": "张三"
} //or操作,满足其中一条就可以查出来
},
{
"match": {
"age": 12
}
}
]
}
}
}
GET /test1/type1/_search
{
"query":{
"bool": {
"must_not": [
{
"match": {
"age": 12 //把不是12岁的人都查询出来
}
}
]
}
}
}
//查询大于9岁小于15岁的张三匹配的文档
GET /test1/type1/_search
{
"query":{
"bool": {
"must": [
{
"match": {
"name": "张三"
}
}
],
"filter": [
{
"range": {
"age": {
"gt": 9,
"lt": 15 //gt:> gte:>= lt:< lte:<=
}
}
}
]
}
}
}
GET /test1/type1/_search
{
"query":{
"match": {
"name": "肖 java" //查询右肖或java的文档,按匹配度排序。
}
}
}
GET _analyze
{
"analyzer": "keyword",
"text": ["肖龙说java name"] //证明keyword不能被拆分
}
GET _analyze
{
"analyzer": "standard",
"text": ["肖龙说java name"]
}
GET /testdb/_search
{
"query": {
"term": { //倒排索引,精确查找
"desc": "肖龙说java desc"
}
}
}
GET /testdb/_search
{
"query": {
"bool": {
"should": [
{
"term": {
"t1": "22"
}
},
{
"term": {
"t1": "23" //精确查询多个值
}
}
]
}
}
}
GET /test1/_search
{
"query": {
"match": {
"name": "肖龙"
}
},
"highlight": {
"fields": {
"name": {} //高亮查询,打上em标签
}
}
}
GET /test1/_search
{
"query": {
"match": {
"name": "肖龙"
}
},
"highlight": {
"pre_tags": "<p class='key' style='color:red>'", //自定义搜索高亮条件
"post_tags": "</p>",
"fields": {
"name": {}
}
}
}