我有以下查询:
{
"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,
}
Run Code Online (Sandbox Code Playgroud)
它返回错误:
"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
}
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
它抱怨这个片段:
{
"nested": {
"path": "languages",
"filters": {
"term": {
"languages.id": "148"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
它曾经工作,但它没有在最新的ES版本.我如何更改此查询以使其工作?
使用嵌套查询替换嵌套过滤器:
"nested" : {
"path" : "languages",
"query" : {
"term": {
"languages.id": "148"
}
}
}
Run Code Online (Sandbox Code Playgroud)
https://www.elastic.co/guide/en/elasticsearch/reference/5.0/query-dsl-nested-query.html
从 Es2.0 开始,嵌套过滤器已被嵌套查询替换。它表现为“查询上下文”中的查询和“过滤器上下文”中的过滤器。
您可以通过@paqash 指定的查询过滤您的文档或
{
"nested" : {
"path" : "languages",
"query": {
"bool": {
"filter": [
{ "term": { "languages.id": "148" }}
]
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我自己没有测试过,但应该按照过滤器上下文中查询子句的文档工作
对于应该影响匹配文档得分的条件(即文档匹配程度),在查询上下文中使用查询子句,并在过滤器上下文中使用所有其他查询子句。
| 归档时间: |
|
| 查看次数: |
4668 次 |
| 最近记录: |