欢迎投稿

今日深度:

elasticsearch中的精准文本位置匹配,

elasticsearch中的精准文本位置匹配,


在elasticsearch中,将长篇幅的文档划分为树形结构的段落后,有助于文本的精准位置匹配,

例如:原来的content是这样的:


content = "一、大标题 \n 1. 一级标题 \n 1> 二级标题"

段落划分后,是如下这样:

content = {
    paras: [
        {
            "text": "大标题",
             "sub_paras": [
                     {
                         "text": "一级标题",
                         "sub_paras": [
                              {
                                  "text": "二级标题"
                                }
                          ]
                      }
              ]
        }
    ]
}



如果在查询时,只想定位到文字所在的段落,可以这样查询:


            "query": {
                "bool": {
                    "should": [
                        {"nested": {
                            "path": "content.paras",
                            "query": {
                                "term": {
                                    "content.paras.text": "哈哈"
                                }
                            },
                            "inner_hits": {
                                "name": "inner_hit_p"
                            }
                        }},
                        {"nested": {
                            "path": "content.paras.sub_paras",
                            "query": {
                                "term": {
                                    "content.paras.sub_paras.text": "哈哈"
                                }
                            },
                            "inner_hits": {
                                "name": "inner_hit_sub_p"
                            }
                        }},
                        {"nested": {
                            "path": "content.paras.sub_paras.sub_paras",
                            "query": {
                                "term": {
                                    "content.paras.sub_paras.sub_paras.text": "哈哈"
                                }
                            },
                            "inner_hits": {
                                "name": "inner_hit_sub_sub_p"
                            }
                        }},
                    ]
                }
            }


www.htsjk.Com true http://www.htsjk.com/Elasticsearch/33796.html NewsArticle elasticsearch中的精准文本位置匹配, 在elasticsearch中,将长篇幅的文档划分为树形结构的段落后,有助于文本的精准位置匹配, 例如:原来的content是这样的: content = "一、大标题 \n 1. 一...
相关文章
    暂无相关文章
评论暂时关闭