Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Elasticsearch中单个或多个文档中的多个单词匹配(全文)_Search_Solr_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Lucene_Full Text Search - Fatal编程技术网 elasticsearch,lucene,full-text-search,Search,Solr,elasticsearch,Lucene,Full Text Search" /> elasticsearch,lucene,full-text-search,Search,Solr,elasticsearch,Lucene,Full Text Search" />

Elasticsearch中单个或多个文档中的多个单词匹配(全文)

Elasticsearch中单个或多个文档中的多个单词匹配(全文),search,solr,elasticsearch,lucene,full-text-search,Search,Solr,elasticsearch,Lucene,Full Text Search,我的要求是: 如果我将多个单词作为列表传递给搜索,ES将返回单词匹配子集以及匹配单词的文档,这样我就可以了解哪个文档与哪个子集匹配。 假设我需要搜索诸如足球、板球、网球、高尔夫等单词。 在三份文件中 我将把这些文件存储在相应的文档中。“mydocuments”索引的映射如下所示: { "mydocuments" : { "mappings" : { "docs" : { "properties" : { "file_content" :

我的要求是:

如果我将多个单词作为列表传递给搜索,ES将返回单词匹配子集以及匹配单词的文档,这样我就可以了解哪个文档与哪个子集匹配。

假设我需要搜索诸如足球、板球、网球、高尔夫等单词。 在三份文件中

我将把这些文件存储在相应的文档中。“mydocuments”索引的映射如下所示:

{
  "mydocuments" : {
    "mappings" : {
      "docs" : {
        "properties" : {
          "file_content" : {
            "type" : "string"
          }
        }
      }
    }
  }
}
第一份文件

{ _id: 1, file_content: "I love tennis and cricket"}
第二份文件:

{ _id: 2, file_content: "tennis and football are very popular"}
{ _id: 3, file_content: "football and cricket are originated in england"}
第三份文件:

{ _id: 2, file_content: "tennis and football are very popular"}
{ _id: 3, file_content: "football and cricket are originated in england"}
我应该能够搜索一个或多个足球、网球、, 板球,高尔夫,它应该会有这样的回报

    "hits":{
        "total" : 3,
        "hits" : [
            {
                "_index" : "twitter",
                "_type" : "tweet",
                "_id" : "1",
                "_source" : {
                    "file_content" : ["football","cricket"],
                    "postDate" : "2009-11-15T14:12:12",

                }
                },
                {
                    "_index" : "twitter",
                    "_type" : "tweet",
                    "_id" : "2",
                    "_source" : {
                        "file_content" : ["football","tennis"],
                        "postDate" : "2009-11-15T14:12:12",

                    }
                }
            ]
像这样的

    "hits":{
        "total" : 3,
        "hits" : [
            {
                "_index" : "twitter",
                "_type" : "tweet",
                "_id" : "1",
                "_source" : {
                    "file_content" : ["football","cricket"],
                    "postDate" : "2009-11-15T14:12:12",

                }
                },
                {
                    "_index" : "twitter",
                    "_type" : "tweet",
                    "_id" : "2",
                    "_source" : {
                        "file_content" : ["football","tennis"],
                        "postDate" : "2009-11-15T14:12:12",

                    }
                }
            ]
或者在多个文件搜索的情况下,使用上述搜索结果的数组

知道我们如何使用Elasticsearch来实现这一点吗

如果使用elasticsearch确实无法做到这一点,我准备评估任何其他选项(Native lucene,Solr)

编辑


我的缺点可能是我没有提供足够的细节@Andrew我所说的文件是以字符串字段(全文)形式存储在ES文档中的文件文本内容。假设一个文件对应于一个名为“file_content”的字段中包含文本内容字符串的文档。

最接近您所需的内容是,这意味着强调文档中搜索的术语

示例查询:

{
  "query": {
    "match": {
      "file_content": "football tennis cricket golf"
    }
  },
  "highlight": {
    "fields": {"file_content":{}}
  }
}
结果:

"hits": { "total": 3, "max_score": 0.027847305, "hits": [ { "_index": "test_highlight", "_type": "docs", "_id": "1", "_score": 0.027847305, "_source": { "file_content": "I love tennis and cricket" }, "highlight": { "file_content": [ "I love <em>tennis</em> and <em>cricket</em>" ] } }, { "_index": "test_highlight", "_type": "docs", "_id": "2", "_score": 0.023869118, "_source": { "file_content": "tennis and football are very popular" }, "highlight": { "file_content": [ "<em>tennis</em> and <em>football</em> are very popular" ] } }, { "_index": "test_highlight", "_type": "docs", "_id": "3", "_score": 0.023869118, "_source": { "file_content": "football and cricket are originated in england" }, "highlight": { "file_content": [ "<em>football</em> and <em>cricket</em> are originated in england" ] } } ] } “点击次数”:{ “总数”:3, “最高分数”:0.027847305, “点击次数”:[ { “_索引”:“测试_突出显示”, “_type”:“docs”, “_id”:“1”, “_分数”:0.027847305, “_来源”:{ “档案内容”:“我喜欢网球和板球” }, “亮点”:{ “文件内容”:[ “我喜欢网球和板球” ] } }, { “_索引”:“测试_突出显示”, “_type”:“docs”, “_id”:“2”, “_分数”:0.023869118, “_来源”:{ “档案内容”:“网球和足球非常受欢迎” }, “亮点”:{ “文件内容”:[ “网球和足球很受欢迎” ] } }, { “_索引”:“测试_突出显示”, “_type”:“docs”, “_id”:“3”, “_分数”:0.023869118, “_来源”:{ “文件内容”:“足球和板球起源于英格兰” }, “亮点”:{ “文件内容”:[ “足球和板球起源于英国” ] } } ] }
正如您所看到的,在一个特殊的
突出显示
部分下突出显示了找到的术语(元素被
标记包围)。

我认为您需要考虑您自己的应用程序,看看ES能给您带来什么,以及您能做些什么,以您希望的方式在自己的应用程序中安排结果<代码>{football:yes,cricket:no,network:yes,golf-no}
是关于你的申请,ES不能给你这样的东西。ES为您提供JSON,这个JSON具有特定的、确定良好的结构。请先阅读关于ES的文档,然后提出一个关于ES的有意义的问题。@Andreastefan:我确实觉得这个问题很有趣,并且认为它是一个通用的ES问题。(免责声明:我是Solr用户。)文件中的文本是标记化的,我想说问题归结为:如果我给ES一些单词,我如何找出这些单词(或由单词生成的标记)中的哪些在哪个文档中?我不认为原始海报需要的是给定的JSON结构,而只是可以从ES返回的JSON结构派生的数据。@BlueM,首先他谈到的是“文件”。在ES中,我们谈论文档。他/她是如何从“文件”变成“文件”的——没有提到这一点。其次,没有映射,您假设“标记化”。好的,如何标记化?他已经有地图了吗?如果有,地图在哪里?海报能否澄清我的JSON声明?目前还没有。第三,仅供参考,SO提供了一些关于如何提问的信息。话虽如此,我确实希望海报能展示他尝试了什么,他到目前为止有什么,还有什么不起作用。我给了他/她一个关于阅读文档的重要建议。@Andreastefan:当然——问题中缺少很多细节,为了简单起见,我对设置做了一些假设。但是:我还是对答案感兴趣:-)@BlueM好的。假设这么多的事情都是“太宽泛”的问题。我将等待帖子的更新。在那之前,我不会试图回答。