0

我有以下查询,我想"Schwarz"在名称字段或消息字段中获取搜索词。语言必须是奥地利语,状态类型应与提供的列表相同。我收到以下异常,但我不知道为什么:

QueryParsingException[[my_test_index] [_na] 查询格式错误,start_object 后没有字段]; }]",

{
        "query": {
            "filtered": {
                "query": {
                    "bool": {
                        "must": [
                            {
                                "bool": {
                                    "should": [
                                        {
                                            "term": {
                                                "name": "Schwarz"
                                            }
                                        },
                                        {
                                            "term": {
                                                "message": "Schwarz"
                                            }
                                        }
                                    ],
                                    "minimum_should_match": 1
                                }
                            },
                            {
                                "terms": {
                                    "status_type": [
                                        "1",
                                        "2",
                                        "3",
                                        "4",
                                        "5",
                                        "6",
                                        "7"
                                    ]
                                }
                            },
                            {
                                "term": {
                                    "language": "Austrian"
                                }
                            }
                        ]
                    }
                }
            }
        },
        "sort": [
            {
                "total": {
                    "order": "desc"
                }
            }
        ]
    }

这是没有过滤器的查询仍然有效:

{
  "query": {
    "filtered": {
      "query": {
        "bool": {
          "should": [
            {
              "match": {
                "standard_analyzed_name": "Schwarz"
              }
            },
            {
              "match": {
                "standard_analyzed_message": "Schwarz"
              }
            }
          ],
          "must": [
            {
              "terms": {
                "buzzsumo_status_type": [
                  "1",
                  "2",
                  "3",
                  "4",
                  "5",
                  "6",
                  "7"
                ]
              }
            },
            {
              "term": {
                "language": "Austrian"
              }
            }
          ]
        }
      }
    }
  },
  "sort": [
    {
      "total_interactions": {
        "order": "desc"
      }
    }
  ]
}
4

1 回答 1

1

在过滤查询中,您必须有一个过滤器部分,此处不存在。我建议像这样重写它,即将termsterm部分移动到filter部分中:

{
  "query": {
    "filtered": {
      "query": {
        "bool": {
          "should": [
            {
              "term": {
                "name": "Schwarz"
              }
            },
            {
              "term": {
                "message": "Schwarz"
              }
            }
          ],
          "minimum_should_match": 1
        }
      },
      "filter": {
        "bool": {
          "must": [
            {
              "terms": {
                "status_type": [
                  "1",
                  "2",
                  "3",
                  "4",
                  "5",
                  "6",
                  "7"
                ]
              }
            },
            {
              "term": {
                "language": "Austrian"
              }
            }
          ]
        }
      }
    }
  },
  "sort": [
    {
      "total": {
        "order": "desc"
      }
    }
  ]
}

另一种方法是不使用filtered查询,而是像这样简单地编写它:

{
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "should": [
              {
                "term": {
                  "name": "Schwarz"
                }
              },
              {
                "term": {
                  "message": "Schwarz"
                }
              }
            ],
            "minimum_should_match": 1
          }
        },
        {
          "terms": {
            "status_type": [
              "1",
              "2",
              "3",
              "4",
              "5",
              "6",
              "7"
            ]
          }
        },
        {
          "term": {
            "language": "Austrian"
          }
        }
      ]
    }
  },
  "sort": [
    {
      "total": {
        "order": "desc"
      }
    }
  ]
}
于 2015-08-06T18:55:37.843 回答