elasticsearch:带有has_parent查询的NullPointerException

时间:2014-03-26 11:30:59

标签: ruby elasticsearch

运行has_parent查询时,我有一个嵌套的NullPointerException。 在下面找到问题的示例查询:

{
  "query": {
    "has_parent": {
      "parent_type": "cluster",
      "query": {
        "match_all": {}
      }
    }
  }
}

我想运行它来查找所有类型为global的文档。 全球文件的一个例子:

     {
        "_index": "cluster",
        "_type": "global",
        "_id": "efd880791b",
        "_score": 1.0,
        "_source": {
          "lppversion": "7.1.1.3",
          "version": "7.1.1 SP4",
          "clustername": "lgeha_cluster"
        },
        "fields": {
          "_parent": "645bb3e3da"
        }
      }

与父母一起:

{
  "_index": "cluster",
  "_type": "cluster",
  "_id": "645bb3e3da",
  "_score": 1.0,
  "_source": {
     "scriptname": "ha_collector.sh"
   }
}

这里是全球的映射:

{
  "index_analyzer": "default_index",
  "search_analyzer": "default_search",
  "_parent": {
    "type": "cluster"
  },
  "_routing": {
    "required": true
  },
  "properties": {
    "lppversion": {
      "type": "string"
    },
    "version": {
      "type": "string"
    },
    "clustername": {
      "type": "string"
    }
  }
}

我使用ruby client libray elasticsearch 1.0.1。

这是错误消息的完整示例:

Elasticsearch::Transport::Transport::Errors::BadRequest: [400] {"error":"SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[9JTe0ya7Q4qSvwhcBGf0DQ][cluster][4]: SearchParseException[[cluster][4]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"has_parent\":{\"parent_type\":\"cluster\",\"query\":{\"match_all\":{}}}}}]]]; nested: NullPointerException; }{[9JTe0ya7Q4qSvwhcBGf0DQ][cluster][3]: SearchParseException[[cluster][3]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"has_parent\":{\"parent_type\":\"cluster\",\"query\":{\"match_all\":{}}}}}]]]; nested: NullPointerException; }{[9JTe0ya7Q4qSvwhcBGf0DQ][cluster][2]: SearchParseException[[cluster][2]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"has_parent\":{\"parent_type\":\"cluster\",\"query\":{\"match_all\":{}}}}}]]]; nested: NullPointerException; }{[9JTe0ya7Q4qSvwhcBGf0DQ][cluster][1]: SearchParseException[[cluster][1]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"has_parent\":{\"parent_type\":\"cluster\",\"query\":{\"match_all\":{}}}}}]]]; nested: NullPointerException; }{[9JTe0ya7Q4qSvwhcBGf0DQ][cluster][0]: SearchParseException[[cluster][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"has_parent\":{\"parent_type\":\"cluster\",\"query\":{\"match_all\":{}}}}}]]]; nested: NullPointerException; }]","status":400}

我对此索引中所有类型的所有查询都有此消息。我有另一个索引与类似的映射完美配合。

如果您有任何想法,我们将不胜感激。

谢谢,

阿兰

2 个答案:

答案 0 :(得分:0)

所以至少我明白发生了什么。它与类型无关。我为父类型不存在的类型创建了一个映射。

"_parent": {
    "type": "not_exist"
  }

所以它意味着 NullPointerException :)没有在网络上的任何地方找到它。

答案 1 :(得分:0)

我认为您需要为“type”更改“parent_type”,因此,您的查询应如下所示:

longFruits = CollectionUtils.select(fruits, Precicate.isBanana)