es版本5.4.1
业务:查询产品线为1,2,3情况下 type不能为1的全部产品信息
对应sql:select * from tb_product where id not in (select id from tb_product where product_line in (1,2,3) and type=1)res
怎么写成es查询呢
业务:查询产品线为1,2,3情况下 type不能为1的全部产品信息
对应sql:select * from tb_product where id not in (select id from tb_product where product_line in (1,2,3) and type=1)res
怎么写成es查询呢
3 个回复
dadaball
赞同来自:
但是7版是可以,可以參考看看GET tb_product/_search
{
"query": {
"bool": {
"must_not": [
{
"bool": {
"must": [
{"terms": {"product_line": [1,2,3]}},
{"term": {"type": 1}}
]
}
}
]
}
}
}
liuxg - Elastic
赞同来自:
must 和 must_not可以并排在一起
POST _search
{
"query": {
"bool": {
"must": {
"term": {
"user": "kimchy"
}
},
"filter": {
"term": {
"tag": "tech"
}
},
"must_not": {
"range": {
"age": {
"gte": 10,
"lte": 20
}
}
},
"should": [
{
"term": {
"tag": "wow"
}
},
{
"term": {
"tag": "elasticsearch"
}
}
],
"minimum_should_match": 1,
"boost": 1
}
}
}
ppppenger
赞同来自:
{
"query": "SELECT * FROM library ORDER BY page_count DESC",
"fetch_size": 10
}
translate API https://www.elastic.co/guide/e ... .html