【问题标题】:Elasticsearch combine two different queries types in one requestElasticsearch 在一个请求中结合了两种不同的查询类型
【发布时间】:2016-01-28 11:36:49
【问题描述】:

我想知道是否有可能组合两种查询类型,在我的情况下,我需要一个 queryString 和过滤查询,每个都必须在不同的字段上进行操作。 过滤后的查询获取$postids中的所有记录 $postids:multiple post_id 的值 查询字符串是在文本中搜索一个单词 目前我需要两个请求来存档: 查询过滤:

GET /myindex1/tweecoms/_search
{
"query" : {
        "filtered" : {
            "filter" : {
                "terms" : {
                    "post_id" : ['.$postids.']
                }
            }
        }
}

query String:

GET /myindex1/tweecoms/_search{
 "query": {
                   "query_string": {
                        "query": "*' . $sujet . '*",
                        "lenient": true
                    }
                    }
}

我试着把它结合起来

GET /myindex1/tweecoms/_search

{
  "query": {
    "bool": {
      "should": [
        {
           "query_string": {
                        "query": "hhhh",
                        "lenient": true
                    }
        },
        {
          "filtered" : {
            "filter" : {
                "terms" : {
                    "post_id" : [0,157]
                }
            }
        }
        }
      ]
    }
  }
}`

但我尝试只运行查询字符串

【问题讨论】:

    标签: php search elasticsearch bigdata


    【解决方案1】:

    我认为您需要在 filtered 子句中编写查询。 This 将帮助您理解。 试试这个

    {
      "query": {
        "filtered": {
          "query": {
            "query_string": {
              "query": "keyword"
            }
          },
          "filter": {
            "terms": {
              "post_id": [0,157]
            }
          }
        }
      }
    }
    

    您的查询的问题是您使用的是 should 子句,它将选择具有给定查询字符串的文档或具有给定 post_ids 的文档。您可以将should 替换为must 并且会得到预期的结果。

    您也可以在查询中使用minimum_should_match 参数

    希望对你有帮助

    【讨论】:

    • 我想要做的是有2个结果,不过滤查询查询字符串我想过滤数据查询字符串我想要查​​询字符串的结果和结果过滤器,这就是我想要的,在第二个查询中,我希望他向我展示 [0,1,2] 中的 post_id 示例 post_id 的记录,并感谢您的回答
    猜你喜欢
    • 1970-01-01
    • 2013-07-05
    • 2022-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多