[英]Elasticsearch ignores query string
我正在使用Elasticsearch查詢數據庫中的作業。 下面是我正在使用的查詢。
該查詢應要求以下內容:
-查詢匹配文本,名稱或描述
-工作必須包含所有給定的類別和細分
但是,我遇到的問題是當我進行查詢並添加細分和類別時。 該查詢被表面上忽略,並且該請求返回具有給定細分和類別的所有作業。
{
"index": "jobs",
"type": "job",
"body": {
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"match": {
"categories": "23"
}
},
{
"match": {
"segments": "10"
}
}
],
"should": [
{
"match": {
"name": "php"
}
},
{
"match": {
"text": "php"
}
},
{
"match": {
"description": "php"
}
}
]
}
},
"filter": {
"nested": {
"path": "networks",
"filter": {
"bool": {
"must": [
{
"term": {
"networks.id": 1
}
},
{
"term": {
"networks.status.raw": "PRODUCTION"
}
},
{
"range": {
"networks.start": {
"lte": "now"
}
}
},
{
"range": {
"networks.end": {
"gte": "now"
}
}
}
]
}
}
}
}
}
},
"aggs": {
"categories": {
"terms": {
"field": "categories"
}
},
"segments": {
"terms": {
"field": "segments"
}
}
}
}
}
附帶說明一下,我正在使用laravel和elasticsearch的php實現,而上面是查詢數組的json_encoded表示形式。 (類型本來可以雜耍)
好吧,我自己弄清楚了:
用must子句中的multi_match代替bool查詢中的should參數將解決我的問題。
{
"index": "jobs",
"type": "job",
"body": {
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "php",
"fields": [
"name",
"text",
"description"
]
}
},
{
"match": {
"segments": "10"
}
}
]
}
},
事實證明它很明顯,因為它在文檔中有所說明:
子句(查詢)應出現在匹配的文檔中。 在沒有must子句的布爾查詢中,一個或多個should子句必須與document匹配 。 可以使用minimum_should_match參數設置應匹配的should子句的最小數量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.