Elasticsearch:查找返回响应文档的单词的索引

Elasticsearch: finding the index of the word for which response document is returned

我正在查询 elasticsearch 并在 return 中获取一个数组。但是 returned 数组包含多个句子。我想找到文档 returned 的单词的索引。 returned 文档的相关部分:

"_id": "AVIcfnn-laLYKmOp14og", “_分数”:0.17643881, "_routing": "1658591699", "_parent": "1658591699", “_资源”: { "heading": "", "paragraphs": [ "Plug And Stitch With New Compact And Portable Electric Sewing Machine It Is Suitable For Many Functions, Like You Can Do Straight Stitch, 4 Step Button Hole, Free Arm For Circular Stitch, Auto Trip Bobbin Winder, Single Touch Reverse Stitch, Good For Quilting,Lace Work,picot,smoking,cording,blind Hem Stitch,zig-zag Stitch, Etc. Smart Look With Low Maintainence And With Inbuilt Electric Motor Of 60 Watts Warranty Period Two Years , And Service Provided By Company At Your Door Step.", "The images represent actual product though color of the image and product may slightly differ.", "Apr 13, 2015" ] },

如何在此数据中找到此文档 returned 的词?

您可以使用 Elasticsearch Highligher,它会在给定的内容中高亮显示匹配的字符串。

{
"query" : {...},
"highlight" : {
    "pre_tags" : ["<tag1>"],
    "post_tags" : ["</tag1>"],
    "fields" : {
        "_all" : {}
    }
 }
}

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-highlighting.html

使用Highlighting.

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-highlighting.html

{
    "query" : {...},
    "highlight" : {
        "fields" : {
            "content" : { fragment_size : 150, number_of_fragments: 1}
        }
    }
}

上面的代码片段将 return 1 个大小为 150 个字符的片段用于匹配。 使用 fragment_sizenumber_of_fragments 以获得最佳效果。