GVKun编程网logo

Elasticsearch:无法在多个字段上进行过滤(elasticsearch 字段太多)

5

针对Elasticsearch:无法在多个字段上进行过滤和elasticsearch字段太多这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展Elasticsearch-如何对多个用户进行el

针对Elasticsearch:无法在多个字段上进行过滤elasticsearch 字段太多这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展Elasticsearch - 如何对多个用户进行 elasticsearch 身份验证、elasticsearch-将嵌套字段与文档中的另一个字段进行比较、elasticsearch5不支持搜索多个字段问题、elasticsearch中多个字段聚合两种方法介绍等相关知识,希望可以帮助到你。

本文目录一览:

Elasticsearch:无法在多个字段上进行过滤(elasticsearch 字段太多)

Elasticsearch:无法在多个字段上进行过滤(elasticsearch 字段太多)

我想{ "query" : { "match_all" :{}}}对elasticsearch 进行过滤,但我不知道…

这是我发送给ES _search方法的内容。

curl -XGET http://localhost:9200/users/location/_search ''-H Accept: application/json'' ''-H Content-Type: application/json''-d ''{   "query":{      "match_all":{}   },   "filter":{      "and":{         "geo_distance":{            "distance":"500km",            "location":{               "lat":48.8,               "lon":2.33            }         },         "term":{            "status":1         }      }   },   "sort":[      {         "_geo_distance":{            "location":[               2.33,               48.8            ],            "order":"asc",            "unit":"km"         }      }   ]}''

但是我总是会收到这个错误:

nested: QueryParsingException[[users] [and] filter does not support [distance]]

而且,如果我删除该"and" :{}选项并仅对geo_distance进行过滤,则可以使用…任何帮助都将是极好的。

干杯

答案1

小编典典

我认为您的and过滤器写有误。该错误表明and过滤器或多或少地在参数方面遇到问题。参见http://www.elasticsearch.org/guide/reference/query-
dsl/and-filter/

尝试以下方法:

{   "query":{      "match_all":{}   },   "filter":{      "and": [         {             "geo_distance": {                "distance":"500km",                "location":{                   "lat":48.8,                   "lon":2.33                }             }         }, {             "term": {                "status":1             }         }]      }   },   "sort":[      {         "_geo_distance":{            "location":[               2.33,               48.8            ],            "order":"asc",            "unit":"km"         }      }   ]}

Elasticsearch - 如何对多个用户进行 elasticsearch 身份验证

Elasticsearch - 如何对多个用户进行 elasticsearch 身份验证

如何解决Elasticsearch - 如何对多个用户进行 elasticsearch 身份验证?

我们正在尝试在 AWS 单独的租户(客户)之上创建管理弹性并分配每个 tetant 到不同的指标。

每个客户都有他的用户名/通行证或类似令牌等''。

我们在 aws 上设置了托管 ES 并与原生 Elastic sdk HighRestClinet

      <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>elasticsearch-rest-high-level-client</artifactId>
        <version>7.10</version>
    </dependency>

一切正常,我们从java代码执行的所有操作,如创建索引/管理/搜索等''

这种代码的和平模拟这里描述的基本身份验证 https://www.elastic.co/guide/en/elasticsearch/client/java-rest/master/_basic_authentication.html

final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
            credentialsProvider.setCredentials(AuthScope.ANY,new UsernamePasswordCredentials(settings.getEsUserName(),settings.getEsUserPass()));
            restClientBuilder.setHttpClientConfigCallback(builder -> builder.setDefaultCredentialsProvider(credentialsProvider));

现在我们为每个客户创建不同的索引,这是可以的,但是

问题是现在我们所有的客户都将使用相同的用户名/密码。

是否有可能以某种方式对多个用户进行处理,拥有多个用户/通行证?

因此每个用户只能与其通过密码验证的索引进行交互。

我看到了这个案例 - https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/fgac.html#fgac-walkthrough-basic

正如我从阅读中了解到的,他们谈论的是 kibana 用户的多租户

我是否遗漏了什么,是否有可能以不同的方式实现我们的目标?

谢谢,

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

elasticsearch-将嵌套字段与文档中的另一个字段进行比较

elasticsearch-将嵌套字段与文档中的另一个字段进行比较

如何解决elasticsearch-将嵌套字段与文档中的另一个字段进行比较?

对于嵌套搜索,您要搜索没有父对象的嵌套对象。不幸的是,没有可以与nested对象一起应用的隐藏联接。

至少在当前,这意味着您不会在脚本中同时收到“父”文档和嵌套文档。您可以通过以下两种方式替换脚本并测试结果来确认这一点:

# Parent Document does not exist
"script": {
  "script": "doc[''primary_content_type_id''].value == 12"
}

# nested Document should exist
"script": {
  "script": "doc[''content.content_type_id''].value == 12"
}

可以 通过在objects上循环来以低于性能的方式执行此操作(而不是天生就让ES使用来为您执行此操作nested)。这意味着您必须将文档和nested文档重新索引为单个文档才能正常工作。考虑到您尝试使用它的方式,这可能并没有太大不同,甚至可能会表现得更好(特别是在缺少替代方法的情况下)。

# This assumes that your default scripting language is Groovy (default in 1.4)
# Note1: "find" will loop across all of the values, but it will
#  appropriately short circuit if it finds any!
# Note2: It would be preferable to use doc throughout, but since we need the
#  arrays (plural!) to be in the _same_ order, then we need to parse the
#  _source. This inherently means that you must _store_ the _source, which
#  is the default. Parsing the _source only happens on the first touch.
"script": {
  "script": "_source.content.find { it.content_type_id == _source.primary_content_type_id && ! it.assigned } != null",
  "_cache" : true
}

我缓存的结果,因为没有动态发生在这里(例如,不比较日期Now为实例),所以它是很安全的高速缓存,从而使未来的查找 快。默认情况下,大多数过滤器都是缓存的,但是脚本是少数例外之一。

由于 必须 比较两个值以确保找到正确的内部对象,因此您正在重复 一些 工作,但这实际上是不可避免的。拥有term过滤器最有可能胜过没有过滤器的情况。

解决方法

我需要比较同一文档中的2个字段,实际值无关紧要。考虑以下文档:

_source: {
    id: 123,primary_content_type_id: 12,content: [
        {
            id: 4,content_type_id: 1
            assigned: true
        },{
            id: 5,content_type_id: 12,assigned: false
        }
    ]
}

我需要找到所有未分配主要内容的文档。我无法找到一种方法来比较primary_content_type_id和嵌套的content.content_type_id以确保它们是相同的值。这是我使用脚本尝试过的。我认为我不了解脚本,但这可能是解决此问题的一种方式:

{
    "filter": {
        "nested": {
            "path": "content","filter": {
                "bool": {
                    "must": [
                        {
                            "term": {
                                "content.assigned": false
                            }
                        },{
                            "script": {
                                "script": "primary_content_type_id==content.content_type_id"
                            }
                        }
                    ]
                }
            }
        }
    }
}

请注意,如果我删除过滤器的脚本部分,并用另一个术语过滤器替换为,并在过滤器的脚本部分content_type_id = 12添加了另一个过滤器,则会很好地工作primary_content_id = 12。问题在于,我将不知道(或对我的用例来说也无关紧要)primary_content_type_idor
的值是什么content.content_type_id。只不过与content_type_id匹配的内容所分配的false无关紧要primary_content_type_id

Elasticsearch是否可以进行此检查?

elasticsearch5不支持搜索多个字段问题

elasticsearch5不支持搜索多个字段问题

各位好:

   小弟在使用elasticsarch5.5.1作为搜索引擎时,想实现可以同时搜索多个字段同时搜索标题和类型,但是按照网上的方法测试了一下,直接返回"query doesn''t support multiple fields" ,麻烦帮忙指导一下为啥不能同时搜索多个字段,谢谢!

 搜索拼写的方法如下: 

$queryData[''query''][''bool''][''should''][''match''] [''title''] = ''长春'';
  $queryData[''query''][''bool''][''should''][''match''] [''businessType'']=1;

{"error":{"root_cause":[{"type":"parsing_exception","reason":"[match] query doesn''t support multiple fields, found [title] and [businessType]","line":1,"col":76}],"type":"parsing_exception","reason":"[match] query doesn''t support multiple fields, found [title] and [businessType]","line":1,"col":76},"status":400}

 

elasticsearch中多个字段聚合两种方法介绍

elasticsearch中多个字段聚合两种方法介绍

两种方式

1、大桶套小桶,通过terms一层层聚合
这个方法适用于需要统计每一项的数据,比如a中有多少种b

2、函数扩展(script)聚合
这个方法适用于直接统计有多少种组合

 

下面是方法2的具体实现:

统计:

复制代码
GET ****_20190926/_search
{
  "size": 0,
  "aggs": {
    "pre": {
      "terms": {
        "script": "doc[''inChannel''].values +''####''+doc[''resCode''].values",
        "size": 5
      }
    }
  }
}
复制代码

结果:

复制代码
{
  "took": 2,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 18,
    "max_score": 0,
    "hits": []
  },
  "aggregations": {
    "pre": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets": [
        {
          "key": "[7220101]####[0]",
          "doc_count": 13
        },
        {
          "key": "[]####[]",
          "doc_count": 2
        },
        {
          "key": "[1020201]####[]",
          "doc_count": 1
        },
        {
          "key": "[10202]####[]",
          "doc_count": 1
        },
        {
          "key": "[7220101]####[]",
          "doc_count": 1
        }
      ]
    }
  }
}
复制代码

java代码参考:

复制代码
Script script = new Script("doc[''inChannel''].values +''####''+ doc[''resCode''].values");

//用于统计每一项详细数据
TermsAggregationBuilder app = AggregationBuilders.terms("app").script(script).size(10000);

//用于统计有多少项
CardinalityAggregationBuilder app = AggregationBuilders.cardinality("app").script(script).precisionThreshold(10000);
复制代码

关于Elasticsearch:无法在多个字段上进行过滤elasticsearch 字段太多的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于Elasticsearch - 如何对多个用户进行 elasticsearch 身份验证、elasticsearch-将嵌套字段与文档中的另一个字段进行比较、elasticsearch5不支持搜索多个字段问题、elasticsearch中多个字段聚合两种方法介绍的相关知识,请在本站寻找。

本文标签: