1

我正在使用 elastic4s 1.5.10 并尝试构建我在 elasticsarch REST 端点上准备的查询。现在尝试重写为elastic4s dsl。

POST /index_name/type/_search
{
    "_source":{"include":["name","surname"]},
   "query": {
      "bool": {
         "must": [
            {
               "more_like_this": {
                  "fields": ["desc"],
                  "ids": ["472825948"],
                  "min_term_freq":0,
                  "max_query_terms":200
               }
            },
            {
               "match": {"city": "London"}
            }, 
            {
               "match": {"operation": "add"}
            }
         ]
      }
   }
}

此查询的目标是获取与在同一城市(伦敦)具有相同操作(添加)的 472825948 相似的项目。

我在 elastic4s 中的尝试如下:

es_client.execute{
      search in  s"$storage_folder/${typ.name()}" query bool(    
        must(
          morelike id adId in s"$storage_folder/${typ.name()}" fields("desc") minTermFreq(0) maxQueryTerms(200),
          matchQuery(field="city",value = "London"),
          matchQuery(field="operation",value = "add"))
      )sourceInclude("name","surname")
    }
  }

“更像”在这种情况下不起作用。原始 json 中的查询没有意义,或者 elastic4s 不支持这个,或者......

有人可以帮忙吗?

谢谢

4

1 回答 1

2

只是为了完整起见,我也来到了这里。 morelikee 是一个请求类型,morelikeThisQuery是查询的正确形式。所以结果查询应该如下所示

es_client.execute{
      search in  s"$storage_folder/${typ.name()}" query bool(    
        must(
          morelikeThisQuery fields("desc")  ids(adId) minTermFreq(0) maxQueryTerms(200),
          matchQuery(field="city",value = "London"),
          matchQuery(field="operation",value = "add"))
      )sourceInclude("name","surname")
    }
  }
于 2015-06-02T07:26:57.073 回答