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 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算