第50节:初识搜索引擎_上机动手实战多搜索条件组合查询
課程大綱
?
GET /website/article/_search
{
? "query": {
??? "bool": {
????? "must": [
??????? {
????????? "match": {
??????????? "title": "elasticsearch"
????????? }
??????? }
????? ],
????? "should": [
??????? {
????????? "match": {
??????????? "content": "elasticsearch"
????????? }
??????? }
????? ],
????? "must_not": [
??????? {
????????? "match": {
??????????? "author_id": 111
????????? }
??????? }
????? ]
??? }
? }
}
?
{
??? "bool": {
??????? "must":???? { "match": { "title": "how to make millions" }},
??????? "must_not": { "match": { "tag":?? "spam" }},
??????? "should": [
??????????? { "match": { "tag": "starred" }}
??????? ],
??????? "filter": {
????????? "range": { "date": { "gte": "2014-01-01" }}
??????? }
??? }
}
?
bool
must,must_not,should,filter
?
每個子查詢都會計算一個document針對它的相關度分數,然后bool綜合所有分數,合并為一個分數,當然filter是不會計算分數的
?
{
??? "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 /company/employee/_search
{//注意單純的filter ,必須添加constant_score
? "query": {
??? "constant_score": {
????? "filter": {
??????? "range": {
????????? "age": {
??????????? "gte": 30
????????? }
??????? }
????? }
??? }
? }
}
?
?
總結
以上是生活随笔為你收集整理的第50节:初识搜索引擎_上机动手实战多搜索条件组合查询的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 移动应用开发跨平台工具imag.js入门
- 下一篇: 睡前故事:风情寡妇村