- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在 Elastic Search 5.0 中获取以多种类型(type1 AND type2 AND type3...)存在的文档。我知道可以通过在 URL 中使用多种类型(如 type1、type2)并过滤 _type 字段来跨多种类型进行搜索。但是所有这些条件都是 OR (type1 OR type2)。如何实现 AND 条件?
这是我的ES中的两个文档,
{
"_index":"cust_58e8700034fa4e368590fb1396e2641c",
"_type":"unique-fp-domains",
"_id":"n_d4dbba7309a94503b25eca735078f17c_258b3ad1a11aba282f35908662bdc5432d68fd96bf3ca90013dcdd5764331399",
"_version":2,
"_score":1,
"_source":{
"mg_timestamp":1579866709096,
"violated-directive":"connect-src",
"fp-hash":"258b3ad1a11aba282f35908662bdc5432d68fd96bf3ca90013dcdd5764331399",
"time":1579866709096,
"scan-id":"n_d4dbba7309a94503b25eca735078f17c",
"blocked-uri":"play.sundaysky.com"
}
}
{
"_index":"cust_58e8700034fa4e368590fb1396e2641c",
"_type":"tag-alexa-top1k-using-csp-tld-domain",
"_id":"AW_XY4P4kmprPQ28bTUb",
"_version":1,
"_score":1,
"_source":{
"tagged-domain":"sundaysky.com",
"tag-guidance":"FP",
"additional-tag-metadata-isbase64-encoded":"eyJ0b3RhbC1hbGV4YS1tYXRjaGVzIjoyMzh9",
"project-id":2,
"fp-hash":"258b3ad1a11aba282f35908662bdc5432d68fd96bf3ca90013dcdd5764331399",
"scan-id":"n_d4dbba7309a94503b25eca735078f17c",
}
}
我想使用 "scan-id":"n_d4dbba7309a94503b25eca735078f17c"
我试过了,
{
"size": 100,
"query": {
"bool": {
"must": [
{
"bool": {
"filter": [
{
"term": {
"_type": {
"value": "tag-alexa-top1k-using-csp-tld-domain"
}
}
},
{
"term": {
"scan-id": {
"value": "n_d4dbba7309a94503b25eca735078f17c"
}
}
}
]
}
},
{
"bool": {
"filter": [
{
"term": {
"_type": {
"value": "unique-fp-domains"
}
}
},
{
"term": {
"scan-id": {
"value": "n_d4dbba7309a94503b25eca735078f17c"
}
}
}
]
}
}
]
}
}
}
但它不起作用。
最佳答案
Elasticsearch 不擅长加入不同的文档集合,但在您的情况下,您可以使用 parent-child
解决您的问题。关系。
如果你有一个 one-to-many relationship你可以用 parent-child
来建模.让我们假设类型 unique-fp-domains
是“父”类型和scan-id
字段是唯一标识符。我们还假设 tag-alexa-top1k-using-csp-tld-domain
是一个“ child ”,每个类型的文档 tag-alexa-top1k-using-csp-tld-domain
在 unique-fp-domains
中恰好引用 1 个文档.
然后我们应该按以下方式创建 Elasticsearch 映射:
PUT /cust_58
{
"mappings": {
"unique-fp-domains": {},
"tag-alexa-top1k-using-csp-tld-domain": {
"_parent": {
"type": "unique-fp-domains"
}
}
}
}
然后像这样插入文档:
# "parent"
PUT /cust_58/unique-fp-domains/n_d4dbba7309a94503b25eca735078f17c
{
"mg_timestamp": 1579866709096,
"violated-directive": "connect-src",
"fp-hash": "258b3ad1a11aba282f35908662bdc5432d68fd96bf3ca90013dcdd5764331399",
"time": 1579866709096,
"scan-id": "n_d4dbba7309a94503b25eca735078f17c",
"blocked-uri": "play.sundaysky.com"
}
# "child"
POST /cust_58/tag-alexa-top1k-using-csp-tld-domain?parent=n_d4dbba7309a94503b25eca735078f17c
{
"tagged-domain": "sundaysky.com",
"tag-guidance": "FP",
"additional-tag-metadata-isbase64-encoded": "eyJ0b3RhbC1hbGV4YS1tYXRjaGVzIjoyMzh9",
"project-id": 2,
"fp-hash": "258b3ad1a11aba282f35908662bdc5432d68fd96bf3ca90013dcdd5764331399",
"scan-id": "n_d4dbba7309a94503b25eca735078f17c"
}
现在我们将能够查询具有任何与其关联的子对象的父对象 == 加入父 ID,这是我们强制为 scan-id
通过提供 _id
手动编辑文档。
查询将使用 has_child
看起来像这样:
POST /cust_58/unique-fp-domains/_search
{
"query": {
"has_child": {
"type": "tag-alexa-top1k-using-csp-tld-domain",
"query": {
"match_all": {}
},
"inner_hits": {}
}
}
}
请注意,我们使用 inner_hits
告诉 Elasticsearch 检索匹配的“子”文档。
输出看起来像:
"hits": [
{
"_index": "cust_58",
"_type": "unique-fp-domains",
"_id": "n_d4dbba7309a94503b25eca735078f17c",
"_score": 1.0,
"_source": {
"mg_timestamp": 1579866709096,
"violated-directive": "connect-src",
...
},
"inner_hits": {
"tag-alexa-top1k-using-csp-tld-domain": {
"hits": {
"total": 1,
"max_score": 1.0,
"hits": [
{
"_type": "tag-alexa-top1k-using-csp-tld-domain",
"_id": "AW_xhfnnIzWDkoWd1czA",
"_score": 1.0,
"_routing": "n_d4dbba7309a94503b25eca735078f17c",
"_parent": "n_d4dbba7309a94503b25eca735078f17c",
"_source": {
"tagged-domain": "sundaysky.com",
...
}
parent-child
有什么缺点? ?If you care about query performance you should not use this query.
在 Elasticsearch 6 中,输入 have been removed .好消息是,从 Elasticsearch 5 开始就可以使用 join
datatype .
总的来说,Elasticsearch 不太擅长管理对象之间的关系,但是there are few ways to deal with them .
希望对您有所帮助!
关于elasticsearch - 跨多个 Elasticsearch 类型查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59929996/
在我的应用程序中播放背景音乐时遇到问题。 首先,我在第一个 Storyboard View Controller 中的 ViewDidLoad 方法中开始播放音乐。即使我从一个页面跳转到另一个页面,它
我想跨行连接数组,然后进行不同的计数。理想情况下,这会起作用: WITH test AS ( SELECT DATE('2018-01-01') as date, 2 as value,
这是一个场景: Repo A 是一个包含大量模块和依赖项的怪异代码。安装起来并不容易。它由其他人维护并托管在 Github 上。 Repo A 包含一个非常有用的模块 X,并且几乎不依赖于 Repo
目前,我在一台服务器上运行了一个应用程序。有一个 crontab 设置,因此根据指定的规则,在某些时间运行任务。 现在,我正在考虑将我的应用程序迁移到 docker 容器中,以便我能够独立运行我的应用
我有一个全局表,我想在两个不同的 Lua 状态之间保持同步。根据我所阅读和理解的内容,唯一的方法似乎是,在我的 C 后端,在状态之间进行表的深层复制(如果表已被修改)。有没有更好的办法 ? 另外,我看
我们目前有一个 asmx webservice,它公开了一个方法来对 Sql 数据库进行各种更新,内部包装在 SqlTransaction 中。 我正在 WCF 中重写此服务,我们希望将现有方法拆分为
我是 Qt 的新手,所以请原谅这个问题的简单性,但我对 Qt 线程有点困惑。假设我有 3 个线程:主要的默认 GUI 线程和我自己创建的 2 个线程(称为 WorkerThread)。我的每个 Wor
我们的产品有一个 Restful API 和一个服务器渲染的应用程序(CMS)。两者共享数据库。两者都是用django编写的 两者所需的字段和模型并不是相互排斥的,有些仅针对 API,有些针对 CMS
我正在实现一个基于角色的访问控制系统,它具有以下数据库表。 groups --------- id (PK) name level resources --------- id (PK) name r
我有三个应用程序,为了便于管理,我希望将它们分开。他们按照建议作为 Plack 服务器运行 here , 代理在 nginx 后面。 我想有一个单独的应用程序来管理登录,并在所有其他应用程序之间共享该
我的主窗口上有一个 UIWebView。我可以通过我的第二个 View Controller 来控制它吗?如果可以的话你能给我举个例子吗? 最佳答案 是的,你可以。 “如何”是一个基本的 Cocoa/
我想制作一个小型应用程序,从连接到串行端口的设备收集数据,并将其通过 LAN 传递到另一个应用程序,后者将其存储在数据库中。 我已经在一台 PC 上的一个应用程序中完成了此操作,因此实际上会将应用程序
从主 AppDomain,我试图调用在不同 AppDomain 中实例化的类型中定义的异步方法。 比如下面的类型MyClass继承自 MarshalByRefObject并在新的 AppDomain
因为 LiveServerTestCase继承自 TransactionTestCase ,默认行为是在每个测试方法结束时删除测试数据。我想用LiveServerTestCase类,但保留方法之间的测
我正在开发我的第一个 WPF/MVVM 应用程序,但我在命令知识方面遇到了限制! 这是我的场景。 我有一个窗口——Customer.xaml。 它包含 2 个用户控件 查看CustomerSearch
这是我的 WPF 应用程序模型的简化版本: Employee +Name:string Client +Name:string +PhoneNumber:string Appointmen
我有一个 mercurial 存储库,它使用子存储库功能(如 .hgsub 文件中定义的)引入依赖项,但我正在努力让它在 TeamCity 中工作。 我启用了 mercurial_keyring 扩展
我正在尝试使用新的 Azure 虚拟网络公共(public)预览版的对等互连功能来加入我在两个不同订阅(即不同租户)上拥有的两个网络。这可能吗?我没有看到任何其他说法,但是当我尝试在 PowerShe
我有 2 个存储库。由于主干代码位于一个 protected 存储库中,因此我进行了 checkout ,然后 checkin 到另一个存储库(因为用户没有第一个 protected 存储库的权限)。
我有一个项目,其调用结构与此类似: 主要项目/应用 我的图书馆代码 别人的库代码 我的图书馆代码 一切都是用 C# 编写的,我可以访问“其他人的库代码”。他们的代码不包含在我的项目中,因为它是开源的而
我是一名优秀的程序员,十分优秀!