身安不如心安,屋宽不如心宽 。

es 使用短语查询的时候,如何检索a and(b OR c) 这种情况

Elasticsearch | 作者 f_on | 发布于2019年02月21日 | 阅读数:3388

"mappings": {"test": {

"properties": {

"WEIBOID": {

"type": "keyword"

},
"LENGTH": {

"type": "integer"

},
"KEYWORD": {

"type": "keyword"

},
"USERRIGHT": {

"type": "integer"

},
"AUTHOR": {

"type": "keyword"

},
"PUBDATE": {

"format": "yyyy-MM-dd HH:mm:ss",
"type": "date"

},
"ABSTRACT": {

"type": "keyword"

},
"URL": {

"type": "keyword"

},
"COMMENTCOUNT": {

"type": "integer"

},
"HEADICONURL": {

"type": "keyword"

},
"STATUS": {

"type": "integer"

},
"WEIBOHOME": {

"type": "keyword"

},
"FEELINGINDEX": {

"type": "float"

},
"FINDDATE": {

"format": "yyyy-MM-dd HH:mm:ss",
"type": "date"

},
"COPYCOUNT": {

"type": "integer"

},
"CONTENT": {

"analyzer": "ik_smart",
"type": "text"

},
"ID": {

"type": "keyword"

},
"DOCTYPE": {

"type": "keyword"

},
"SYS_VSM": {

"type": "keyword"

},
"REMARK": {

"type": "integer"

},
"TYPE": {

"type": "keyword"

},
"WEBWEIGHT": {

"type": "integer"

},
"MSGID": {

"type": "keyword"

},
"IP": {

"type": "ip"

},
"DIGEST": {

"type": "keyword"

},
"CACHE": {

"index": false,
"type": "text"

},
"SOURCETYPE": {

"type": "keyword"

},
"REGION": {

"type": "keyword"

},
"SOURCE": {

"type": "keyword"

},
"RELRES": {

"type": "integer"

},
"TITLE": {

"analyzer": "ik_smart",
"type": "text"

},
"ACCESSORIES": {

"type": "keyword"

},
"HITCOUNT": {

"type": "integer"

},
"URLID": {

"type": "keyword"

},
"WEBSITE": {

"type": "keyword"

}

}

}
 
dsl
 

{
"query": {
"bool": {
"must": [{
"query_string": {
"query": "+ 标准 + (国新办||2018)",
"fields": ["TITLE"],
"type": "phrase"
}
}, {
"terms": {
"SOURCETYPE": [2]
}
}, {
"range": {
"PUBDATE": {
"gt": "2019-01-01 00:00:00",
"lt": "2019-03-01 00:00:00"
}
}
}]
}
},
"_source": {
"includes": ["TITLE"]
},
"size": 100,
"from": 0,
"sort": [{
"_score": "desc"
}]
}
 
 
 
 
结果如下图。。。标准两字匹配到了  为啥标准+国新办这种数据没匹配到呢???
sc.png sc1.png
已邀请:

rochy - rochy_he

赞同来自:

"query": {
"bool": {
"must": [
{
"term": {
"title": "中国"
}
},
{
"bool": {
"should": [
{
"term": {
"title": "减少"
}
},
{
"term": {
"title": "无法"
}
}
]
}
}
]
}
}
如果你需要 中国一定要排在前面就使用,matchPhraseQuery 用两个 boolQuery 将 "
中国减少
" 和 "中国无法" 组合起来即可

要回复问题请先登录注册