检索时的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": {}
}
}