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 信号发生器如何将频率调大,步尽值改成10
  • ¥15 keil 5 编程智能家具,风扇台灯开关,人体感应等
  • ¥100 找一名渗透方面的专家
  • ¥20 使用Matlab gui设计一个插补小程序
  • ¥15 evo评估时曲线出现问题
  • ¥15 eNSP拓扑图配置实验
  • ¥20 有没有兄弟会替换fmod studio的.bank文件内的音效?
  • ¥20 如何解决访问网址被屏蔽的情况
  • ¥15 本地运行的vue2项目,使用内网穿透,前端界面一直转圈圈
  • ¥20 powerbuilder datawindow控件导出Excel数据,可不可以不自动覆盖原数据,而是在后面新插入入数据。