drf97973 2013-10-25 14:26
浏览 210
已采纳

使用ElasticSearch匹配多个文档

I am relatively new to ElasticSearch. I am using it as a search platform for pdf documents. I break the PDFs into text-pages and enter each one as an elasticSearch record with it's corresponding page ID, parent info, etc.

What I'm finding difficult is matching a given query not only to a single document in ES, but making it match any document with the same parent ID. So if two terms are searched, if the terms existed on page 1 and 7 of the actual PDF document (2 separate entries into ES), I want to match this result.

Essentially my goal is to be able to search through the multiple pages of a single PDF, matching happening on any of the document-pages in the PDF, and to return a list of matching PDF documents for the search result, instead of matching "pages"

  • 写回答

2条回答 默认 最新

  • doudun6928 2013-10-25 15:27
    关注

    It's somewhat tricky. First of all, you will have to split your query into terms yourself. Having a list of terms (let's say foo, bar and baz, you can create a bool query against type representing PDFs (parent type) that would look like this:

    {
        "bool" : {
            "must" : [{
                "has_child" : {
                    "type": "page",
                    "query": {
                        "match": {
                            "page_body": "foo"
                        }
                    }
                }
            }, {
                "has_child" : {
                    "type": "page",
                    "query": {
                        "match": {
                            "page_body": "bar"
                        }
                    }
                }
            }, {
                "has_child" : {
                    "type": "page",
                    "query": {
                        "match": {
                            "page_body": "baz"
                        }
                    }
                }
            }]
       }
    }
    

    This query will find you all PDFs that contain at least one page with each term.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Stata链式中介效应代码修改
  • ¥15 latex投稿显示click download
  • ¥15 请问读取环境变量文件失败是什么原因?
  • ¥15 在若依框架下实现人脸识别
  • ¥15 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错