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 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符