2016-08-15 52 views
1

我是Elasticsearch和Nest的新手,請原諒我的無知。我想在Elasticsearch v2.3.5中使用過濾器和multi_match查詢,但到目前爲止我無法弄清楚。我想,一旦我爲Elasticsearch工作,我應該能夠將它映射到Nest。Elasticsearch v2.3.5中的過濾器和multi_match查詢

下面是我的JSON數據結構:

{ 
    "contentID":1, 
    "categoryID":0, 
    "title":"...", 
    "description":"...", 
    "contentHtml":"...", 
    "version":2, 
    "parentContentID":0, 
    "displayOrder":0, 
    "freshdeskID":0, 
    "isDraft":false, 
    "isCommentingEnabled":false, 
    "isArticle":false, 
    "grandParentContentID":0, 
    "isAnyParentDraft":false 
} 

以下是我的工作搜索查詢(無任何過濾器):

POST contents/supportitem/_search?pretty=true 
{ 
    "size": 150, 
    "highlight": { 
    "fields": { 
     "contentHtml": { 
     "fragment_size": 245 
     } 
    } 
    }, 
    "_source": { 
    "include": [ 
     "title", 
     "contentID", 
     "description", 
     "thumbnailUrl", 
     "isDraft", 
     "isAnyParentDraft", 
     "grandParentContentID" 
    ] 
    },"query": { 
    "multi_match": { 
     "type": "cross_fields", 
     "query": "query typed by user", 
     "tie_breaker": 0.3, 
     "fields": [ 
     "title^1.1", 
     "additionalContents^1.2", 
     "contentHtml^1" 
     ] 
    } 
    } 
} 

我想只顯示在搜索結果的記錄用戶其中:

grandParentContentID != 0 and 
isDraft != false and 
isAnyParentDraft != false 

我試過了可能是不同的查詢但我無法弄清楚如何寫這個。

夫婦不工作的查詢,包括:

POST contents/supportitem/_search?pretty=true 
{ 
    "size": 150, 
    "highlight": { 
    "fields": { 
     "contentHtml": { 
     "fragment_size": 245 
     } 
    } 
    }, 
    "_source": { 
    "include": [ 
     "title", 
     "contentID", 
     "description", 
     "thumbnailUrl", 
     "isDraft", 
     "isAnyParentDraft", 
     "grandParentContentID" 
    ] 
    },"query": { 
    "multi_match": { 
     "type": "cross_fields", 
     "query": "Tile map server resources", 
     "tie_breaker": 0.3, 
     "fields": [ 
     "title^1.1", 
     "additionalContents^1.2", 
     "contentHtml^1" 
     ] 
    },"filtered": { 
     "filter": { 
     "bool": { 
      "term": { 
      "isAnyParentDraft": "false" 
      } 
     } 
     } 
    } 
    } 
} 


POST contents/supportitem/_search?pretty=true 
{ 
    "size": 150, 
    "highlight": { 
    "fields": { 
     "contentHtml": { 
     "fragment_size": 245 
     } 
    } 
    }, 
    "_source": { 
    "include": [ 
     "title", 
     "contentID", 
     "description", 
     "thumbnailUrl", 
     "isDraft", 
     "isAnyParentDraft", 
     "grandParentContentID" 
    ] 
    },"query": { 
    "multi_match": { 
     "type": "cross_fields", 
     "query": "Tile map server resources", 
     "tie_breaker": 0.3, 
     "fields": [ 
     "title^1.1", 
     "additionalContents^1.2", 
     "contentHtml^1" 
     ] 
    },"filtered": { 
     "query": { 
     "bool": { 
      "must": [ 
      { 
       "field": {"isAnyParentDraft": "false"} 
      } 
      ] 
     } 
     } 
    } 
    } 
} 

我得到"failed to parse search source. expected field name but got [START_OBJECT]"

我得到這個工作,但我無法弄清楚如何添加更多的過濾器:

POST contents/supportitem/_search?pretty=true 
{ 
    "size": 150, 
    "highlight": { 
    "fields": { 
     "contentHtml": { 
     "fragment_size": 245 
     } 
    } 
    }, 
    "_source": { 
    "include": [ 
     "title", 
     "contentID", 
     "description", 
     "thumbnailUrl", 
     "isDraft", 
     "isAnyParentDraft", 
     "grandParentContentID" 
    ] 
    }, 
    "query": { 
    "filtered": { 
     "query": { 
     "multi_match": { 
      "type": "cross_fields", 
      "query": "deleted", 
      "tie_breaker": 0.3, 
      "fields": [ 
      "title^1.1", 
      "additionalContents^1.2", 
      "contentHtml^1" 
      ] 
     } 
     }, 
     "filter": { 
     "and": { 
      "filters": [ 
      { 
       "term": { 
       "isAnyParentDraft": "false" 
       } 
      } 
      ] 
     } 
     } 
    } 
    } 
} 

我提到了以下問題:

ElasticSearch with multi_match AND bool - 只有一個過濾器

Elasticsearch: multi_match no effect with filters

回答

2

非常良好的開端,你幾乎沒有:

POST contents/supportitem/_search?pretty=true 
{ 
    "size": 150, 
    "highlight": { 
    "fields": { 
     "contentHtml": { 
     "fragment_size": 245 
     } 
    } 
    }, 
    "_source": { 
    "include": [ 
     "title", 
     "contentID", 
     "description", 
     "thumbnailUrl", 
     "isDraft", 
     "isAnyParentDraft", 
     "grandParentContentID" 
    ] 
    }, 
    "query": { 
    "bool": { 
     "must": { 
     "multi_match": { 
      "type": "cross_fields", 
      "query": "deleted", 
      "tie_breaker": 0.3, 
      "fields": [ 
      "title^1.1", 
      "additionalContents^1.2", 
      "contentHtml^1" 
      ] 
     } 
     }, 
     "must_not": [ 
     { 
      "term": { 
      "isAnyParentDraft": "false" 
      } 
     }, 
     { 
      "term": { 
      "isDraft": "false" 
      } 
     }, 
     { 
      "term": { 
      "grandParentContentID": 0 
      } 
     } 
     ] 
    } 
    } 
} 
相關問題