Elastic Search 查询

检索时的EndPoint的介绍<br/> /_search<br/> 在所有的索引中搜索所有的类型<br/> /gb/_search<br/> 在 gb 索引中搜索所有的类型<br/> /gb,us/_search<br/> 在 gb 和 us 索引中搜索所有的文档<br/> /g*,u*/_search<br/> 在任何以 g 或者 u 开头的索引中搜索所有的类型<br/> /gb/user/_search<br/> 在 gb 索引中搜索 user 类型<br/> /gb,us/user,tweet/_search<br/> 在 gb 和 us 索引中搜索 user 和 tweet 类型<br/> /_all/user,tweet/_search 在所有的索引中搜索 user 和 tweet 类型

查询语法
 { "query": YOUR_QUERY_HERE}
"match_all": {}//查询所有
"match": {"content": "全文匹配"  } //分词搜索
"match_phrase": { "content": "路哥"  }//习语匹配
"wildcard": {  "region": "43*" }//通配符匹配
"terms":{"id":[99980,99927]} //匹配多个精确值
"range":{"id":{"gte":199,"lte":1000}}// 范围匹配
"regex": {  "region": "43*" } //正则匹配

合并查询语句

{
    "bool": {
        "must":     { "match": { "tweet": "elasticsearch" }}, 
        "must_not": { "match": { "name":  "mary" }},
        "should":   { "match": { "tweet": "full text" }},
        "filter":   { "range": { "age" : { "gt" : 30 }} }//filter context 没有评分 只返回查到或者没查到 在query context下会返回一个评分 来判定匹配程度 如果需要在filter下加must should等 再加一层bool就可以
    }
}

一个组合查询的例子

{
    "size": 20, "from": 0,
    "query": {
        "bool": {
            "must": [
                {
                    "wildcard": {
                        "region": "43*"
                    }
                },{
                    "range":{
                	"id":{"gte":199,"lte":1000}
                    }
                }
            ]
        }
    },
    "_source": [ 
        "infotype",
        "classify",
        "deletetime"
    ],//指定返回的字段
    "sort": [
        {
            "id": {
                "order": "desc"
            }
        }
    ]//排序
}

删除所有 <host>:<port>/<index>/<type>/_delete_by_query 再删除的时候会发生版本冲突 发生10次就会终止请求 不会回滚 需要解决版本冲突加上参数conflicts=proceed 官方文档 官方中文文档

{
  "query": {
    "match_all": {}
  }
}

转载于:https://my.oschina.net/jing21/blog/1556348

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值