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
Exception Elasticsearch查询“空索引”_Exception_Search_Indexing_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Mapping - Fatal编程技术网 elasticsearch,mapping,Exception,Search,Indexing,elasticsearch,Mapping" /> elasticsearch,mapping,Exception,Search,Indexing,elasticsearch,Mapping" />

Exception Elasticsearch查询“空索引”

Exception Elasticsearch查询“空索引”,exception,search,indexing,elasticsearch,mapping,Exception,Search,Indexing,elasticsearch,Mapping,在我的应用程序中,我使用了几个elasticsearch索引,它们在初始状态下不包含索引文档。我认为这可以称为空: 文档的映射正确且有效 该应用程序还有一个包含实体的关系数据库,这些实体可能有与elasticsearch关联的文档 在应用程序的初始状态中,通常只有没有文档的实体,因此没有一个文档被索引,因此索引为空。尽管如此,索引还是被创建了,文档的映射也被放置到了索引中,并且存在于索引元数据中 无论如何,当我使用SearchQuery查询elasticsearch以查找其中一个实体的文档时,该

在我的应用程序中,我使用了几个elasticsearch索引,它们在初始状态下不包含索引文档。我认为这可以称为空: 文档的映射正确且有效

该应用程序还有一个包含实体的关系数据库,这些实体可能有与elasticsearch关联的文档

在应用程序的初始状态中,通常只有没有文档的实体,因此没有一个文档被索引,因此索引为空。尽管如此,索引还是被创建了,文档的映射也被放置到了索引中,并且存在于索引元数据中

无论如何,当我使用SearchQuery查询elasticsearch以查找其中一个实体的文档时,该文档包含来自该实体的唯一id,elasticsearch将抛出ElasticSearchException,该异常抱怨字段xy等不存在映射

但是如果我先在索引中插入一个空白文档,查询就不会失败

有没有一种方法可以初始化索引,以防止查询失败并摆脱愚蠢的虚拟文档解决方案

更新:
另外,虚拟文档的解决方案会污染索引,例如计数查询现在总是返回+1…因此我也在解决方案中添加了一个删除…

搜索时是否进行排序?我遇到了同样的问题,没有为[field]找到映射以便进行排序,但只有在尝试对结果进行排序时。在这种情况下,解决方案只是将ignore_unmapped:true属性添加到查询中的sort参数:

{
  ...
  "body": {
    ...
    "sort": [
      {"field_name": {
        "order": "asc",
        "ignore_unmapped": true
      }}
    ]
    ...
  }
  ...
}
我在这里找到了解决方案:

搜索时是否正在进行排序?我遇到了同样的问题,没有为[field]找到映射以便进行排序,但只有在尝试对结果进行排序时。在这种情况下,解决方案只是将ignore_unmapped:true属性添加到查询中的sort参数:

{
  ...
  "body": {
    ...
    "sort": [
      {"field_name": {
        "order": "asc",
        "ignore_unmapped": true
      }}
    ]
    ...
  }
  ...
}
我在这里找到了解决方案:
你的问题缺乏细节,也不清楚。若您提供了索引模式和查询的要点,那个将有所帮助。您还应该提供正在使用的elasticsearch版本

您提到的映射异常与使用某些数据初始化索引无关。很可能是在不存在的字段上排序。如果一次查询多个索引,这是很常见的

解决方案:解决方案基于elasticsearch的版本。如果您使用的是1.3.x或更低版本,则应使用“忽略未映射”。如果您使用的版本大于1.3.5,则应使用未映射类型。

如果您发现文档令人困惑,那么本例将说明:

让我们创建两个索引testindex1和testindex2

这两个索引之间的唯一区别是-testindex1有服务器字段,而textindex2有计算机字段

现在,让我们在两个索引中插入测试数据

测试INDEX1上的索引测试数据:

testindex2上的索引测试数据:

查询示例:

对elasticsearch版本>1.3.x使用未映射的_类型

    curl -XPOST 'localhost:9200/testindex2/_search?pretty' -d '{"fields":["firstname"],"query":{"match_all":{}},"sort":[{"servers.location.name":{"order":"desc","unmapped_type":"string"}}]}'

使用elasticsearch版本的ignore_unmapped你的问题缺乏细节,也不清楚。若您提供了索引模式和查询的要点,那个将有所帮助。您还应该提供正在使用的elasticsearch版本

您提到的映射异常与使用某些数据初始化索引无关。很可能是在不存在的字段上排序。如果一次查询多个索引,这是很常见的

解决方案:解决方案基于elasticsearch的版本。如果您使用的是1.3.x或更低版本,则应使用“忽略未映射”。如果您使用的版本大于1.3.5,则应使用未映射类型。

如果您发现文档令人困惑,那么本例将说明:

让我们创建两个索引testindex1和testindex2

这两个索引之间的唯一区别是-testindex1有服务器字段,而textindex2有计算机字段

现在,让我们在两个索引中插入测试数据

测试INDEX1上的索引测试数据:

testindex2上的索引测试数据:

查询示例:

对elasticsearch版本>1.3.x使用未映射的_类型

    curl -XPOST 'localhost:9200/testindex2/_search?pretty' -d '{"fields":["firstname"],"query":{"match_all":{}},"sort":[{"servers.location.name":{"order":"desc","unmapped_type":"string"}}]}'

为elasticsearch版本使用ignore_unmapped是您定义映射还是elasticsearch在索引时自动检测映射?否我为每个文档类型明确定义映射。您是定义映射还是elasticsearch在索引时自动检测映射?否我为每个文档类型明确定义映射。
    curl -XPOST 'localhost:9200/testindex2/_search?pretty' -d '{"fields":["firstname"],"query":{"match_all":{}},"sort":[{"servers.location.name":{"order":"desc","unmapped_type":"string"}}]}'
curl -XPOST 'localhost:9200/testindex2/_search?pretty' -d '{"fields":["firstname"],"query":{"match_all":{}},"sort":[{"servers.location.name":{"order":"desc","ignore_unmapped":"true"}}]}'
{
  "took" : 15,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 2,
    "max_score" : null,
    "hits" : [ {
      "_index" : "testindex2",
      "_type" : "type1",
      "_id" : "1",
      "_score" : null,
      "fields" : {
        "firstname" : [ "computertom" ]
      },
      "sort" : [ null ]
    }, {
      "_index" : "testindex2",
      "_type" : "type1",
      "_id" : "2",
      "_score" : null,
      "fields" : {
        "firstname" : [ "computerjerry" ]
      },
      "sort" : [ null ]
    } ]
  }
}
{
  "took" : 10,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 2,
    "max_score" : null,
    "hits" : [ {
      "_index" : "testindex2",
      "_type" : "type1",
      "_id" : "1",
      "_score" : null,
      "fields" : {
        "firstname" : [ "computertom" ]
      },
      "sort" : [ -9223372036854775808 ]
    }, {
      "_index" : "testindex2",
      "_type" : "type1",
      "_id" : "2",
      "_score" : null,
      "fields" : {
        "firstname" : [ "computerjerry" ]
      },
      "sort" : [ -9223372036854775808 ]
    } ]
  }
}