我正在使用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")
}
}
“morelike”在这种情况下不起作用。原始json中的查询没有意义,或者elastic4s不支持这个或......
有人可以帮忙吗?
THX
答案 0 :(得分:2)
为了完整性添加回复,我也来到了这里。
morelike
e代表请求类型,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")
}
}