elasticseach如何在请求正文中添加搜索类型

时间:2018-05-29 22:30:58

标签: ruby-on-rails elasticsearch elasticsearch-5 chewy-gem

我有一个查询,我将search_type用作

GET /test_videos/_search?search_type=dfs_query_then_fetch&explain=true
{
  "query": {
    "bool": {
      "must": {
        "multi_match": {
                  "query": "funny",
                  "fields": ["title"]
                 }
              }
            }
}
}

工作正常并给出我想要的结果。

我也可以像这样在身体中指定解释:

GET /test_claim_videos/_search?search_type=dfs_query_then_fetch
{ "explain" : true,
  "query": {
    "bool": {
      "must": {
        "multi_match": {
                  "query": "funny",
                  "fields": ["title", "asset_name", "description", "tags.name", "asset_group_name.humanized", "credit"]
                 }
              }
            }
}
}

但是我想在主体内部将search_type指定为dfs_then_fetch。 如果我做

GET /test_claim_videos/_search
{ "search_type" : "dfs_query_then_fetch",
  "explain" : true,
  "query": {
    "bool": {
      "must": {
        "multi_match": {
                  "query": "funny",
                  "fields": ["title", "asset_name", "description", "tags.name", "asset_group_name.humanized", "credit"]
                 }
              }
            }
}
}

它引发了错误:

{
  "error": {
    "root_cause": [
      {
        "type": "parsing_exception",
        "reason": "Unknown key for a VALUE_STRING in [search_type].",
        "line": 1,
        "col": 19
      }
    ],
    "type": "parsing_exception",
    "reason": "Unknown key for a VALUE_STRING in [search_type].",
    "line": 1,
    "col": 19
  },
  "status": 400
}

为什么我不能在这里指定搜索类型以及如何解决?我需要它在身体,因为我正在使用第三方宝石耐嚼,它不允许传递URL。

2 个答案:

答案 0 :(得分:0)

不幸的是你无法做到这一点。您可以在documentation中了解更多信息:

  

除此之外,search_type和request_cache必须作为查询字符串参数传递。

答案 1 :(得分:0)

如果有人知道具体答案请帮帮忙。现在我将我的分片/索引减少到1,它可以正常工作。