elasticsearch ElasticSearch:在ElasticSearch中的等效运算符中
我试图在SQL中找到等价于
elasticsearch ElasticSearch:在ElasticSearch中的等效运算符中,
elasticsearch,
elasticsearch,我试图在SQL中找到等价于\而不是的ElasticSearch查询 我知道我们可以使用查询字符串查询多个OR来获得相同的答案,但最终会得到很多OR 任何人都可以分享这个例子吗?与Chris建议的注释类似,在中类似地替换(查询意味着评分,这可能会改善返回的订单) 等效的Elasticsearch 1.x过滤器为: { "query" : { "filtered" : { "filter" : { "terms" : { "id" : [1
\而不是的ElasticSearch查询
我知道我们可以使用查询字符串查询多个OR来获得相同的答案,但最终会得到很多OR
任何人都可以分享这个例子吗?与Chris建议的注释类似,在
中类似地替换(查询意味着评分,这可能会改善返回的订单)
等效的Elasticsearch 1.x过滤器为:
{
"query" : {
"filtered" : {
"filter" : {
"terms" : {
"id" : [1, 2, 3]
}
}
}
}
}
{
"query" : {
"bool" : {
"filter" : {
"terms" : {
"id" : [1, 2, 3]
}
}
}
}
}
等效的Elasticsearch 2.x+过滤器为:
{
"query" : {
"filtered" : {
"filter" : {
"terms" : {
"id" : [1, 2, 3]
}
}
}
}
}
{
"query" : {
"bool" : {
"filter" : {
"terms" : {
"id" : [1, 2, 3]
}
}
}
}
}
重要的一点是,术语
过滤器(以及针对该问题的查询)处理精确匹配。它隐式地是一个或
操作,类似于
中的
如果你想反转它,你可以使用not过滤器,但我建议使用稍微详细一点的bool
/must\u not
过滤器(养成同样使用bool
/must
和bool
的习惯)
总的来说,bool
复合查询语法与term
(单数)和terms
过滤器(复数,如图所示)相同。我看到了您的要求。
我写的源代码如下
我希望这能帮助你解决你的问题
sql查询:
select * from tablename where fieldname in ('AA','BB');
弹性搜索:
{
query :{
bool:{
must:[{
"script": {
"script":{
"inline": "(doc['fieldname'].value.toString().substring(0,2).toUpperCase() in ['AA','BB']) == true"
}
}
}],
should:[],
must_not:[]
}
}
}
1术语
您可以在ElasticSearch中使用术语术语查询,其作用与中相同
术语查询用于检查值是否与数组中提供的任何值匹配
2不得
不得可在ElasticSearch中用作not
前
存在
此外,如果有帮助,您还可以使用“存在”查询来检查字段是否存在。
例如,
检查该字段是否存在
"exists" : {
"field" : "mobileNumber"
}
检查字段是否不存在
"bool":{
"must_not" : [
{
"exists" : {
"field" : "mobileNumber"
}
}
]
}
首先:在ES和Java/Painless中,有更简单的方法来创建“startsWith”样式的字符串。第二:这与SQL查询不同。我的原始答案在这里仍然正确。如果数组大小为800或更多,上述查询的时间复杂度是多少?这里的限制是什么。有最大数组大小吗?
"bool":{
"must_not" : [
{
"exists" : {
"field" : "mobileNumber"
}
}
]
}