match分词搜索
全文搜索- match_all 搜索全部
GET xxx/_search
{
"query":{
"match_all":{}
}
}
匹配单字段搜索
- field 字段名
GET xxx/_search { "query":{ "match":{ "field":"内容" } } }
匹配单字段多词组搜索
- filed 字段名,词组使用空格隔开
GET xxx/_search
{
“query”:{
“match”:{
“field”:“内容1 内容2 内容3”
}
}
}
匹配多字段搜索
- must相当于MySQL条件中的 AND
- should相当于MySQL条件中的 OR
GET xxx/_search
{
“query”:{
“bool”:{
“must”:[
{
“match”:{
“field1”:“content”
}
},
{
“match”:{
“field2”:“content”
}
}
]
}
}
}
should
GET xxx/_search
{
“query”:{
“bool”:{
“should”:[
{
“match”:{
“field1”:“content”
}
},
{
“match”:{
“field2”:“content”
}
}
]
}
}
}
匹配多字段搜索相同内容
- multi_match 多字段
- query 搜索内容
- fields 搜索的字段
- operator 字段的匹配方式 ,属性有OR, AND
GET xxx/_search
{
"query":{
"multi_match": {
"query": "content",
"fields": ["field_name1", "field_name2"],
"operator": "OR"
}
}
}
搜索分页
- from 起始数
- size 获得的数量
GET xxx/_search
{
"query":{
"match_all":{}
},
"from":0,
"size":10
}
搜索过滤
- filter 过滤
- field 要过滤的字段名
- gte 大于等于 附加 gt 大于
- lte 小于等于 附加 lt 小于
GET xxx/_search
{
"query":{
"bool":{
"should":[
{
"match_all":{}
}
],
"filter":{
"range":{
"field":{
"gte":22,
"lte":23
}
}
}
}
}
}
term精确搜索
精确搜索- term 精确查找(单个)
- terms 精确查找(多个)
term
{ "query":{ "term": { "_id":1 } } }
terms{ "query":{ "terms": { "_id":[1,2,3] } } }
term高亮搜索
高亮搜索
- highlight 高亮查找
- pre_tags 标签前缀
- post_tags 标签后缀
- fields 规定的字段,支持多个
<em></em>
{
“query”:{
“match”:{
“field”:“content”
}
},
“highlight”:{
“pre_tags”:“<p class = “text_high_light”>”,
“post_tags”:“</p>”,
“fields”:{
“field”:{}
}
}
}