【问题标题】:Elastic search With MongoDB : Searching PDFs使用 MongoDB 进行弹性搜索:搜索 PDF
【发布时间】:2012-10-29 13:42:33
【问题描述】:

我试图将我的 pdf 文件保存在 Mongo Db 的 gridFS 中,然后使用弹性搜索在该 pdf 中进行搜索。我执行了以下操作:

1) Mongo DB 端:

mongod --port 27017 --replSet rs0 --dbpath "D:\Mongo-DB\mongodb-win32-i386-2.0.7\data17"
mongod --port 27018 --replSet rs0 --dbpath "D:\Mongo-DB\mongodb-win32-i386-2.0.7\data18"
mongod --port 27019 --replSet rs0 --dbpath "D:\Mongo-DB\mongodb-win32-i386-2.0.7\data19"

mongo localhost:27017
rs.initiate()
rs.add("hostname:27018")
rs.add("hostname:27019")

mongofiles -hlocalhost:27017 --db testmongo --collection files --type application/pdf put D:\Sherlock-Holmes.pdf

2) 弹性搜索端(已安装插件:bigdesk/head/mapper-attachments/river-mongodb)

-> 使用来自“任何请求”选项卡的以下请求的弹性搜索头

URL : http://localhost:9200/_river/mongodb/
_meta/PUT

{
  "type": "mongodb",
  "mongodb": {
    "db": "testmongo",
    "collection": "fs.files",
    "gridfs": true,
    "contentType": "",
    "content": "base64 /path/filename | perl -pe 's/\n/\\n/g'"
  },
  "index": {
    "name": "testmongo",
    "type": "files",
    "content_type": "application/pdf"
  }
}

现在我正在尝试访问以下网址:

http://localhost:9200/testmongo/files/508e82e21e43def09b5e1602?pretty=true

我得到以下回复(我相信这是预期的):

{
  "_index" : "testmongo",
  "_type" : "files",
  "_id" : "508e82e21e43def09b5e1602",
  "_version" : 1,
  "exists" : true, "_source" : {"_id":"508e82e21e43def09b5e1602","filename":"D:\\Sherlock-Holmes.pdf","chunkSize":262144,"uploadDate":"2012-10-29T13:21:38.969Z","md5":"025fa2046f9254d2aecb9e52ae851065","length":98272,"contentType":"application/pdf"}
}

但是当我尝试使用以下 URL 搜索此 pdf 时:

http://localhost:9200/testmongo/files/_search?q=Albers&pretty=true

它给了我以下结果:

{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 0,
    "max_score" : null,
    "hits" : [ ]
  }
}

这里它显示我没有任何命中,但这个 pdf 中出现了“Albers”这个词。请帮忙。提前致谢。

【问题讨论】:

    标签: mongodb elasticsearch


    【解决方案1】:

    我认为您必须指定要搜索的属性

    http://localhost:9200/testmongo/files/_search?q=<PROPERTYNAME>:Albers&pretty=true
    

    甚至是复杂的搜索

    $ curl -XPOST 'http://localhost:9200testmongo/files/_search?q' -d '{
        <PROPERTYNAME> : "value",
        <PROPERTYNAME> : {
                              <PROPERTYNAME> : "value",
                              <PROPERTYNAME> : "value"
                         }
    }
    '
    

    但据我所知,您只能在索引数据后搜索您定义的属性。

    【讨论】:

    • 我阅读了文档,我们可以使用 ES 搜索不同的附件类型文本 [如 pdf/doc 等],因为 ES 内部使用 apache TIKA 从不同文件中获取文本。在您的解决方案中,我们将如何根据不同文件的实际文本创建属性?
    • 我只在弹性搜索方面做了一点工作,但据我了解弹性搜索附件它只索引附件的元数据。所以这些元数据应该可以用于搜索,如date、title、author、keywords。这些数据应该可以像my_attachment.author 这样的属性来访问,例如
    猜你喜欢
    • 2018-01-10
    • 1970-01-01
    • 2013-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-22
    • 2017-03-31
    相关资源
    最近更新 更多