2021-11MongoDB全文检索-12

本文介绍了如何在MongoDB中导入数据,并通过示例展示了创建、删除文本索引的过程。接着,演示了如何进行基于文本的搜索,包括使用AND、OR、NOT操作符以及聚合管道进行高级查询。此外,还提到了查询结果的分数排序。
摘要由CSDN通过智能技术生成

1.  导入数据

[hadoop@hadoop1 bin]$ mongod -f mongodb.conf &

[1] 3702

[hadoop@hadoop1 bin]$ mongoimport --db catalog --collection books --type json --drop --file /opt/module/mongodb/tmp/catalog.books.json 

2020-09-24T19:34:10.398+0800 connected to: localhost

2020-09-24T19:34:10.399+0800 dropping: catalog.books

2020-09-24T19:34:10.448+0800 imported 431 documents

> use catalog

switched to db catalog

> show collections

books

> db.books.find().count()

431

> db.books.findOne()

  1. 定义文本索引

//weights 使用到了weights权重,给对于的字段设置权重,那么查询到该字段后的结果分值将乘以对应的权重,提示分数值。

> db.books.createIndex( {title: 'text',shortDescription: 'text',longDescription: 'text',     authors: 'text',categories: 'text'},{weights:{title: 10,shortDescription: 1,longDescription:1,authors: 1,categories: 5}});

{

"createdCollectionAutomatically" : false,

"numIndexesBefore" : 1,

"numIndexesAfter" : 2,

"ok" : 1

}

> db.books.stats()

{

"ns" : "catalog.books",

"size" : 517474,

"count" : 431,

"avgObjSize" : 1200,

"storageSize" : 311296,

"capped" : false,

"wiredTiger" : {

"metadata" : {

"formatVersion" : 1

},

"creationString" : "access_pattern_hint=none,allocation_size=4KB,app_metadata=(formatVersion=1),assert=(commit_timestamp=none,read_timestamp=none),block_allocation=best,block_compressor=snappy,cache_resident=false,checksum=on,colgroups=,collator=,columns=,dictionary=0,encryption=(keyid=,name=),exclusive=false,extractor=,format=btree,huffman_key=,huffman_value=,ignore_in_memory_cache_size=false,immutable=false,internal_item_max=0,internal_key_max=0,internal_key_truncate=true,internal_page_max=4KB,key_format=q,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=32KB,leaf_value_max=64MB,log=(enabled=true),lsm=(auto_throttle=true,bloom=true,bloom_bit_count=16,bloom_config=,bloom_hash_count=8,bloom_oldest=false,chunk_count_limit=0,chunk_max=5GB,chunk_size=10MB,merge_custom=(prefix=,start_generation=0,suffix=),merge_max=15,merge_min=0),memory_page_max=10m,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=false,prefix_compression_min=4,source=,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=90,type=file,value_format=u",

"type" : "file",

"uri" : "statistics:table:collection-0-6135922527786654092",

"LSM" : {

"bloom filter false positives" : 0,

"bloom filter hits" : 0,

"bloom filter misses" : 0,

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值