2017-03-06 62 views
1

我有以下查询:嵌套查询不支持滤镜

{ 
    "query": { 
    "filtered": { 
     "query": { 
     "bool": { 
      "should": [ 
      { 
       "wildcard": { 
       "translations.title": { 
        "value": "*abc*", 
        "boost": 2 
       } 
       } 
      }, 
      { 
       "wildcard": { 
       "translations.subtitle": { 
        "value": "*abc*", 
        "boost": 1.9 
       } 
       } 
      }, 
      { 
       "match": { 
       "translations.title": { 
        "query": "abc", 
        "fuzziness": 5 
       } 
       } 
      }, 
      { 
       "match": { 
       "translations.subtitle": { 
        "query": "abc", 
        "fuzziness": 5 
       } 
       } 
      }, 
      { 
       "wildcard": { 
       "series.translations.title": { 
        "value": "*abc*", 
        "boost": 0.5 
       } 
       } 
      }, 
      { 
       "wildcard": { 
       "translations.subtitle": { 
        "value": "*abc*", 
        "boost": 0.5 
       } 
       } 
      }, 
      { 
       "wildcard": { 
       "tags.text": { 
        "value": "*abc*", 
        "boost": 1.5 
       } 
       } 
      }, 
      { 
       "match": { 
       "tags.text": { 
        "query": "abc", 
        "fuzziness": 5 
       } 
       } 
      }, 
      { 
       "wildcard": { 
       "translations.content": { 
        "value": "*abc*" 
       } 
       } 
      } 
      ] 
     } 
     }, 
     "filter": { 
     "and": [ 
      { 
      "term": { 
       "type": "video" 
      } 
      }, 
      { 
      "term": { 
       "videoType": "brightcove" 
      } 
      }, 
      { 
      "type": { 
       "value": "post-en" 
      } 
      }, 
      { 
      "term": { 
       "isPublished": true 
      } 
      }, 
      { 
      "term": { 
       "status": "published" 
      } 
      }, 
      { 
      "term": { 
       "CategoryId": "4" 
      } 
      }, 
      { 
      "range": { 
       "contentDuration": { 
       "from": "300001" 
       } 
      } 
      }, 
      { 
      "nested": { 
       "path": "languages", 
       "filters": { 
       "term": { 
        "languages.id": "148" 
       } 
       } 
      } 
      } 
     ] 
     } 
    } 
    }, 
    "size": 20, 
    "from": 0, 
} 

并返回错误:

"error": { 
    "root_cause": [ 
     { 
     "type": "query_parsing_exception", 
     "reason": "[nested] query does not support [filters]", 
     "index": "nowness", 
     "line": 1, 
     "col": 1003 
     } 
    ], 
    "type": "search_phase_execution_exception", 
    "reason": "all shards failed", 
    "phase": "query_fetch", 
    "grouped": true, 
    "failed_shards": [ 
     { 
     "shard": 0, 
     "index": "nowness", 
     "node": "Wuh8rSunQ5mdAa2j-RYOBA", 
     "reason": { 
      "type": "query_parsing_exception", 
      "reason": "[nested] query does not support [filters]", 
      "index": "nowness", 
      "line": 1, 
      "col": 1003 
     } 
     } 
    ] 
    } 
} 

它抱怨这个片段:

{ 
      "nested": { 
       "path": "languages", 
       "filters": { 
       "term": { 
        "languages.id": "148" 
       } 
       } 
      } 
      } 

它用来工作,但它并不在最新的ES版本中。我如何改变这个查询来使它工作?

回答

1

从ES2.0,The nested filter has been replaced by the Nested Query。它在“查询上下文”中表现为查询,在“过滤器上下文”中表现为过滤器。

您通过@paqash 或

指定既可以通过查询筛选文件
{ 
    "nested" : { 
     "path" : "languages", 
     "query": { 
     "bool": { 
      "filter": [ 
      { "term": { "languages.id": "148" }} 
      ] 
     } 
     } 
    } 
} 

我没有测试它自己,而是应该按照documentation on query clauses in filter context

Use query clauses in query context for conditions which should affect the score of matching documents (i.e. how well does the document match), and use all other query clauses in filter context.

+0

这将会是工作如果他们会在次要版本更新之间留下至少一个该死的东西相同的话,那就太棒了。 –