当前位置: 首页 > news >正文

MongoDB聚合:$listSearchIndexes

$listSearchIndexes返回指定集合现有Atlas Search索引的信息。

**重要:**该命令只能在托管的MongoDB Allas,并且要求群集层级至少为M10。

语法

db.<collection>.aggregate([{$listSearchIndexes:{id: <indexId>,name: <indexName>}}]
)

参数说明:

  • id,字符串,可选参数,要查询索引的id
  • name,字符串,可选参数,要查询索引的名称

不能同时指定idname,必须要有listSearchIndexes的权限:

访问控制

{resource: {db : <database>,collection: <collection>},actions: [ "listSearchIndexes" ]
}

内置读角色提供listSearchIndexes权限。下面的示例授予了qa数据库的read角色:

db.grantRolesToUser("<user>",[ { role: "read", db: "qa" } ]
)

输出字段

$listSearchIndexes返回一个文档数组,数组中的每个文件都包含以下字段:

字段类型描述
id字符串索引的唯一标识
name字符串索引名称
status字符串索引状态
queryable布尔索引是否已经准备好被查询
latestDefinitionVersion文档索引版本
latestDefinitionVersion.version整数索引定义的版本,当更新索引定义时,版本号会自动增加
latestDefinitionVersion.createdAt日期索引定义创建的时间
latestDefinition文档最新的索引定义
statusDetail文档数组包含了每个搜索主机(mongot)上的索引状态
statusDetail.[n].hostname字符串相应的mongot的主机名
statusDetail.[n].status字符串相应的mongot的索引状态
statusDetail.[n].queryable布尔相应的mongot的索引是否可被查询
statusDetail.[n].mainIndex文档相应的mongot的活动索引的状态
statusDetail.[n].stagedIndex文档包含了相应mongot上,在后台构建的索引的状态信息。该字段只会出现在构建一个索引去更新已存在索引的时候
synonymMappingStatus字符串索引的同义词映射状态,该字段只会出现在索引有同义词定义时。可以是BUILDINGFAILEDREADY这个三个值之一。返回的状态是每个独立mongot上同义词映射的概括
synonymMappingStatusDetail文档数组该字段(和其子字段)只有当索引有同义词定义时才会出现。包含了每个搜索主机(mongot)的索引的同义词映射状态
synonymMappingStatusDetail.[n].status字符串所有mongot进程中相应同义词映射的状态
synonymMappingStatusDetail.[n].queryable布尔表示相应的同义词映射是否支持跨所有mongot进程的查询
message字符串描述同义词映射的错误(如果适用)。只有当该同义词映射的状态为FAILED时才会出现

索引状态详情

下表描述了statusDetail.[mongot].mainIndexstatusDetail.[mongot].stagedIndex文档的内嵌字段:

这些字段描述了特定mongot的索引状态。

|字段|类型|描述|
|-|-|
|status|字符串|相应mongot上索引的生成状态|
|queryable|布尔|相应mongot上索引是否可被查询|
|synonymMappingStatus|字符串|索引生成的同义词映射在相应mongot上的状态。只有当索引定义了同义词时才会出现|
|synonymMappingStatusDetails|文档|包含索引的同义词映射在相应mongot上的状态。该字段(及其子字段)只有在索引定义了同义词时才会出现|
|definitionVersion|文档|描述生成索引时使用的索引定义版本。
|definitionVersion.version|整数|索引生成在相应mongot上使用的版本号。更新索引定义时,更新后的索引的版本号将递增|
|definitionVersion.createdAt|日期|创建索引定义的时间|
|definition|文档|建立该索引时使用的定义|

同义词映射详细信息

下表描述了以下对象的嵌入字段:

  • statusDetail.mainIndex.synonymMappingStatusDetails.<synonymMapping>
  • statusDetail.stagedIndex.synonymMappingStatusDetails<synonymMapping>

|字段|类型|描述|
|-|-|
|status|字符串|跨mongot进程的同义词映射的状态。|
|queryable|布尔|指示同义词映射是否可以支持对相应mongot进程的查询。|
|message|字符串|描述同义词映射的错误(如果适用)。只有当该同义词映射的状态为FAILED时才会出现|

Atlas Search索引状态

$listSearchIndexesstatus字段可以是下面的值:

状态描述
BUILDING当编辑后,Atlas构建或重建索引时或当Atlas Search无法跟上采集索引的变化时(会在后台重建索引),状态为BUILDING;当索引处于BUILDDING时,对于新建索引,Atlas Search不能使用索引查询直到索引构建完成;对于新建索引,Atlas Search会先试用旧索引定义,直到新索引建好后
FAILED索引构建失败,索引可能因索引定义无效而进入FAILED状态
PENDINGAtlas 尚未开始构建索引
READY索引就绪可以用于查询
STALE索引可查询,但已停止从索引集合复制数据。对该索引的搜索可能会返回过期数据。由于复制错误,索引可能会进入STALE状态

错误

7.0.3 版中的更改:此命令在非Atlas上执行时会出错:

db.names.aggregate( [{ $listSearchIndexes: { } }
] )
MongoServerError: PlanExecutor error during aggregation :: caused by :: Search index commands are only supported with Atlas.

在以前的版本中,如果在非Atlas上执行该命令,则返回空结果。

举例

返回所有查询索引

下面的示例将返回电影收藏中的所有Atlas Search索引:

db.movies.aggregate([{$listSearchIndexes: { }}]
)

输出:

[{id: '6524096020da840844a4c4a7',name: 'default',status: 'BUILDING',queryable: true,latestDefinitionVersion: {version: 2,createdAt: ISODate("2023-10-09T14:51:57.355Z")},latestDefinition: {mappings: { dynamic: true },storedSource: { include: [ 'awards.text' ] }},statusDetail: [{hostname: 'atlas-n1cm1j-shard-00-02',status: 'BUILDING',queryable: true,mainIndex: {status: 'READY',queryable: true,definitionVersion: {version: 0,createdAt: ISODate("2023-10-09T14:08:32.000Z")},definition: { mappings: { dynamic: true, fields: {} } }},stagedIndex: {status: 'PENDING',queryable: false,definitionVersion: {version: 1,createdAt: ISODate("2023-10-09T14:51:29.000Z")},definition: {mappings: { dynamic: true, fields: {} },storedSource: true}}},{hostname: 'atlas-n1cm1j-shard-00-01',status: 'BUILDING',queryable: true,mainIndex: {status: 'READY',queryable: true,definitionVersion: {version: 0,createdAt: ISODate("2023-10-09T14:08:32.000Z")},definition: { mappings: { dynamic: true, fields: {} } }},stagedIndex: {status: 'PENDING',queryable: false,definitionVersion: {version: 1,createdAt: ISODate("2023-10-09T14:51:29.000Z")},definition: {mappings: { dynamic: true, fields: {} },storedSource: true}}},{hostname: 'atlas-n1cm1j-shard-00-00',status: 'BUILDING',queryable: true,mainIndex: {status: 'READY',queryable: true,definitionVersion: {version: 0,createdAt: ISODate("2023-10-09T14:08:32.000Z")},definition: { mappings: { dynamic: true, fields: {} } }}}]},{id: '65240be420da840844a4d077',name: 'synonym_mappings',status: 'READY',queryable: true,latestDefinitionVersion: {version: 0,createdAt: ISODate("2023-10-09T14:19:16.305Z")},latestDefinition: {mappings: {dynamic: true,fields: {fullplot: { type: 'string' }}},synonyms: [{name: 'synonym_mapping',analyzer: 'lucene.english',source: { collection: 'synonyms' }}]},synonymMappingStatus: 'READY',synonymMappingStatusDetail: [{synonym_mapping: {status: 'READY',queryable: true}}],statusDetail: [{hostname: 'atlas-n1cm1j-shard-00-02',status: 'READY',queryable: true,mainIndex: {status: 'READY',queryable: true,definitionVersion: {version: 0,createdAt: ISODate("2023-10-09T14:19:16.000Z")},definition: {mappings: {dynamic: true,fields: {fullplot: {type: 'string',indexOptions: 'offsets',store: true,norms: 'include'}}},synonyms: [{name: 'synonym_mapping',analyzer: 'lucene.english',source: { collection: 'synonyms' }}]},synonymMappingStatus: 'READY',synonymMappingStatusDetail: [{synonym_mapping: {status: 'READY',queryable: true}}]}},{hostname: 'atlas-n1cm1j-shard-00-01',status: 'READY',queryable: true,mainIndex: {status: 'READY',queryable: true,definitionVersion: {version: 0,createdAt: ISODate("2023-10-09T14:19:16.000Z")},definition: {mappings: {dynamic: true,fields: {fullplot: {type: 'string',indexOptions: 'offsets',store: true,norms: 'include'}}},synonyms: [{name: 'synonym_mapping',analyzer: 'lucene.english',source: { collection: 'synonyms' }}]},synonymMappingStatus: 'READY',synonymMappingStatusDetail: [{synonym_mapping: {status: 'READY',queryable: true}}]}},{hostname: 'atlas-n1cm1j-shard-00-00',status: 'READY',queryable: true,mainIndex: {status: 'READY',queryable: true,definitionVersion: {version: 0,createdAt: ISODate("2023-10-09T14:19:16.000Z")},definition: {mappings: {dynamic: true,fields: {fullplot: {type: 'string',indexOptions: 'offsets',store: true,norms: 'include'}}},synonyms: [{name: 'synonym_mapping',analyzer: 'lucene.english',source: { collection: 'synonyms' }}]},synonymMappingStatus: 'READY',synonymMappingStatusDetail: [{synonym_mapping: {status: 'READY',queryable: true}}]}}]}
]

按名称返回单个搜索索引

下面的示例将返回电影集合中名为synonym-mappings的索引:

db.movies.aggregate([{$listSearchIndexes:{name: "synonym-mappings"}}]
)

结果为:

[{id: '65240be420da840844a4d077',name: 'synonym_mappings',status: 'READY',queryable: true,latestDefinitionVersion: {version: 0,createdAt: ISODate("2023-10-09T14:19:16.305Z")},latestDefinition: {mappings: {dynamic: true,fields: {fullplot: { type: 'string' }}},synonyms: [{name: 'synonym_mapping',analyzer: 'lucene.english',source: { collection: 'synonyms' }}]},synonymMappingStatus: 'READY',synonymMappingStatusDetail: [{synonym_mapping: {status: 'READY',queryable: true}}],statusDetail: [{hostname: 'atlas-n1cm1j-shard-00-02',status: 'READY',queryable: true,mainIndex: {status: 'READY',queryable: true,definitionVersion: {version: 0,createdAt: ISODate("2023-10-09T14:19:16.000Z")},definition: {mappings: {dynamic: true,fields: {fullplot: {type: 'string',indexOptions: 'offsets',store: true,norms: 'include'}}},synonyms: [{name: 'synonym_mapping',analyzer: 'lucene.english',source: { collection: 'synonyms' }}]},synonymMappingStatus: 'READY',synonymMappingStatusDetail: [{synonym_mapping: {status: 'READY',queryable: true}}]}},{hostname: 'atlas-n1cm1j-shard-00-01',status: 'READY',queryable: true,mainIndex: {status: 'READY',queryable: true,definitionVersion: {version: 0,createdAt: ISODate("2023-10-09T14:19:16.000Z")},definition: {mappings: {dynamic: true,fields: {fullplot: {type: 'string',indexOptions: 'offsets',store: true,norms: 'include'}}},synonyms: [{name: 'synonym_mapping',analyzer: 'lucene.english',source: { collection: 'synonyms' }}]},synonymMappingStatus: 'READY',synonymMappingStatusDetail: [{synonym_mapping: {status: 'READY',queryable: true}}]}},{hostname: 'atlas-n1cm1j-shard-00-00',status: 'READY',queryable: true,mainIndex: {status: 'READY',queryable: true,definitionVersion: {version: 0,createdAt: ISODate("2023-10-09T14:19:16.000Z")},definition: {mappings: {dynamic: true,fields: {fullplot: {type: 'string',indexOptions: 'offsets',store: true,norms: 'include'}}},synonyms: [{name: 'synonym_mapping',analyzer: 'lucene.english',source: { collection: 'synonyms' }}]},synonymMappingStatus: 'READY',synonymMappingStatusDetail: [{synonym_mapping: {status: 'READY',queryable: true}}]}}]}
]

按id返回单个搜索索引

下面的示例以提供的id返回搜索索引:

db.movies.aggregate([{$listSearchIndexes:{id: "6524096020da840844a4c4a7"}}]
)

结果:

[{id: '6524096020da840844a4c4a7',name: 'default',status: 'BUILDING',queryable: true,latestDefinitionVersion: {version: 2,createdAt: ISODate("2023-10-09T14:51:57.355Z")},latestDefinition: {mappings: { dynamic: true },storedSource: { include: [ 'awards.text' ] }},statusDetail: [{hostname: 'atlas-n1cm1j-shard-00-02',status: 'BUILDING',queryable: true,mainIndex: {status: 'READY',queryable: true,definitionVersion: {version: 0,createdAt: ISODate("2023-10-09T14:08:32.000Z")},definition: { mappings: { dynamic: true, fields: {} } }},stagedIndex: {status: 'PENDING',queryable: false,definitionVersion: {version: 1,createdAt: ISODate("2023-10-09T14:51:29.000Z")},definition: {mappings: { dynamic: true, fields: {} },storedSource: true}}},{hostname: 'atlas-n1cm1j-shard-00-01',status: 'BUILDING',queryable: true,mainIndex: {status: 'READY',queryable: true,definitionVersion: {version: 0,createdAt: ISODate("2023-10-09T14:08:32.000Z")},definition: { mappings: { dynamic: true, fields: {} } }},stagedIndex: {status: 'PENDING',queryable: false,definitionVersion: {version: 1,createdAt: ISODate("2023-10-09T14:51:29.000Z")},definition: {mappings: { dynamic: true, fields: {} },storedSource: true}}},{hostname: 'atlas-n1cm1j-shard-00-00',status: 'BUILDING',queryable: true,mainIndex: {status: 'READY',queryable: true,definitionVersion: {version: 0,createdAt: ISODate("2023-10-09T14:08:32.000Z")},definition: { mappings: { dynamic: true, fields: {} } }}}]}
]
http://www.lryc.cn/news/299692.html

相关文章:

  • Excel练习:日历
  • 【C语言】指针练习篇(上),深入理解指针---指针和数组练习题和sizeof,strlen的对比【图文讲解,详细解答】
  • 2048游戏C++板来啦!
  • 2000-2021年县域指标统计数据库
  • Hive on Spark配置
  • 计算机网络——11EMail
  • 第13讲创建图文投票
  • Vulnhub靶机:DC3
  • 代码随想录算法训练营第三十一天|● 理论基础 ● 455.分发饼干 ● 376. 摆动序列 ● 53. 最大子序和
  • 【光学】学习记录1-几何光学的近轴理论
  • 【51单片机】AT24C02(江科大、爱上半导体)
  • nohup基本使用
  • postgresql 手动清理wal日志的101个坑
  • 【开源训练数据集3】Top3人脸数据集及其使用方法-计算机视觉应用
  • 精灵图,字体图标,CSS3三角
  • .NET Core性能优化技巧
  • 人类智能远远超越了物理与数理范畴
  • 数据库管理-第149期 Oracle Vector DB AI-01(20240210)
  • FlinkSql通用调优策略
  • Linux在云计算领域的重要作用
  • sqlserver2012 解决日志大的问题 bat脚本
  • SpringCloud之Eureka注册中心和负载均衡
  • Python 数据可视化之山脊线图 Ridgeline Plots
  • VTK 三维场景的基本要素(相机) vtkCamera 相机的运动
  • C++ //练习 6.53 说明下列每组声明中的第二条语句会产生什么影响,并指出哪些不合法(如果有的话)。
  • 缓慢变化维 常用的处理方法
  • free pascal:fpwebview 组件通过JSBridge调用本机TTS
  • C语言静态库深入剖析
  • A股上市以来涨幅排行榜
  • 鸿蒙开发系列教程(十八)--页面内动画(1)