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_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch - Fatal编程技术网 elasticsearch,Search,elasticsearch" /> elasticsearch,Search,elasticsearch" />

使用Elasticsearch在单个文档中搜索

使用Elasticsearch在单个文档中搜索,search,elasticsearch,Search,elasticsearch,如果我想搜索索引,我可以使用: $curl -XGET 'X/index1/_search?q=title:ES' $curl -XGET 'X/index1/docType1/_search?q=title:ES' 如果要搜索文档类型,可以使用: $curl -XGET 'X/index1/_search?q=title:ES' $curl -XGET 'X/index1/docType1/_search?q=title:ES' 但如果我想搜索特定文档,这不起作用: $curl -XG

如果我想搜索索引,我可以使用:

$curl -XGET 'X/index1/_search?q=title:ES'
$curl -XGET 'X/index1/docType1/_search?q=title:ES'
如果要搜索文档类型,可以使用:

$curl -XGET 'X/index1/_search?q=title:ES'
$curl -XGET 'X/index1/docType1/_search?q=title:ES'
但如果我想搜索特定文档,这不起作用:

$curl -XGET 'X/index1/docType1/documentID/_search?q=title:ES'

是否有一个简单的解决方法,以便我可以在单个文档中搜索,而不是在整个索引或整个文档类型中搜索?为了解释我为什么需要这个,我必须做一些资源密集型的查询来找到我要找的东西。一旦我找到了我需要的文档,我实际上并不需要整个文档,只需要匹配查询的突出显示部分。但我不想将所有突出显示的点击都存储在内存中,因为我可能在几个小时内不需要它们,有时它们可能会占用大量空间(我也不希望将它们写入磁盘)。我宁愿存储一个文档ID列表,这样当我需要文档的突出显示部分时,我就可以在特定文档上运行突出显示的查询并返回突出显示的部分。提前感谢您的帮助

您可以将文档的id作为字段索引,然后在查询时,将唯一的文档id作为一个术语包含进来,以便将结果仅限于单个文档

'$curl -XPOST 'X/index1/docType1/_search' -d '{
    "query": {
        "bool": {
              "must":[
                  {"match":{"doc":"223"}},
                  {"match":{"title":"highlight me please"}}
               ]
        }
   }
}'
您可以使用in-Elasticsearch搜索单个文档。默认情况下,Elasticsearch为名为的字段编制索引,该字段是类型和id的组合,因此可用于查询、聚合、脚本和排序

因此,您需要的查询如下

curl -XGET 'X/index1/_search' -d '{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "title": "ES"
          }
        },
        {
          "ids": {
            "type" : "docType1",
            "values": [
              "documentID"
            ]
          }
        }
      ]
    }
  }
}'
如果需要搜索多个文档,请在ids查询的值数组中指定文档ID