将此mysql查询转换为弹性搜索
我需要将此mysql查询转换为弹性搜索:将此mysql查询转换为弹性搜索,mysql,
elasticsearch,Mysql,
elasticsearch,我需要将此mysql查询转换为弹性搜索: select title, id, slug, is_cinema, release_date from media where media.is_active = 1 AND media_type_id IN (1,3) and CASE media.media_type_id WHEN 1 THEN is_home = 1 ELSE is_home = 0 END and
select title, id, slug, is_cinema, release_date
from media
where media.is_active = 1
AND media_type_id IN (1,3)
and CASE media.media_type_id WHEN 1 THEN is_home = 1 ELSE is_home = 0 END
and MATCH(title) AGAINST("*foo bar*" IN BOOLEAN MODE)
ORDER by is_cinema DESC, CASE WHEN title LIKE "foo bar%" THEN 0 ELSE 1 END ASC, CASE media.media_type_id WHEN 3 THEN 0 when 1 then 1 ELSE 3 end ASC, release_date DESC limit 10;
我已经这样做了如下,我得到了搜索结果。但是我需要添加这个“CASE media.media\u type\u id,当1时为\u home=1,当1时为\u home=0 END”
,并按与顶部完全匹配的顺序下单“order by is\u cinema DESC,CASE WHEN title LIKE“foo bar%”,当标题为“foo bar%”时为CASE media\u type\u id,当1时为0,当3时为0,当1时为1时为0,当1时为1时为0,当1时为1时为1,则为3结束ASC,发布日期描述限制10”
。我用过前缀,但对我来说不太合适
以下是我使用的elasticsearch查询:
GET default/media/_search?pretty
{
"query":{
"filtered": {
"query": {
"bool": {
"should": [
{
"match": {
"title": {
"query": "foo bar",
"boost": 2
}
}
},
{
"match_phrase": {
"title": {
"query": "foo bar",
"boost": 3
}
}
}
]
}
},
"filter": {
"bool": {
"must": [
{
"term":{
"is_active":1
}
},
{
"bool": {
"should": [
{
"term":{
"media_type_id":1
}
},
{
"term":{
"media_type_id":3
}
}
]
}
}
]
}
}
}
}
用
media\u typpe=1和is\u home=1或media\u typpe替换您的case
结构会有帮助吗=1,并且是_home=0
?@cars10当然。。这正是我们对这个案例的期望