在ElasticSearch中,我有自动生成_id字段的文档。我需要通过这个_id进行搜索。不幸的是,当_id是以第一个字符作为自动生成时,无法搜索它。我应该在这个字段上设置映射吗? (到目前为止,我没有整个索引的映射)
请参阅以下通过GETting http://localhost:9200/cazv/issue/_search?pretty=true&q=*:*
..., {
"_index" : "cazv",
"_type" : "issue",
"_id" : "vvQWnjYqSU2GJ4hrRnOBXw",
"_score" : 1.0,
"_source":{"volumeId": "At8YmsUdRqmqX-OUJKvdcQ",
"number": "No. 3"}
}, {
"_index" : "cazv",
"_type" : "issue",
"_id" : "-yTCu-HxSkOhwDOp4JVblg",
"_score" : 1.0,
"_source":{"volumeId": "Z97A5vG8TOSl7Bv0UlFGYg",
"number": "No. 1"}
}
, ...
当我尝试查找第一个问题时,使用http://localhost:9200/cazv/issue/_search?pretty=true&q=_id:vvQWnjYqSU2GJ4hrRnOBXw
我得到了
{
"took" : 137,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [ {
"_index" : "cazv",
"_type" : "issue",
"_id" : "vvQWnjYqSU2GJ4hrRnOBXw",
"_score" : 1.0,
"_source":{"volumeId": "At8YmsUdRqmqX-OUJKvdcQ",
"number": "No. 3"}
} ]
}
}
但是当我试图通过http://localhost:9200/cazv/issue/_search?pretty=true&q=_id:-yTCu-HxSkOhwDOp4JVblg
我收到了错误:
{
"error" : "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[NfwFTkfwTAuyO6QGG9hUUw][cazv][0]: SearchParseException[[cazv][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"query_string\":{\"query\":\"_id:-yTCu-HxSkOhwDOp4JVblg\",\"lowercase_expanded_terms\":true,\"analyze_wildcard\":false}}}]]]; nested: QueryParsingException[[cazv] Failed to parse query [_id:-yTCu-HxSkOhwDOp4JVblg]]; nested: ParseException[Cannot parse '_id:-yTCu-HxSkOhwDOp4JVblg': Encountered \" \"-\" \"- \"\" at line 1, column 4.\r\nWas expecting one of:\r\n <BAREOPER> ...\r\n \"(\" ...\r\n \"*\" ...\r\n <QUOTED> ...\r\n <TERM> ...\r\n <PREFIXTERM> ...\r\n <WILDTERM> ...\r\n <REGEXPTERM> ...\r\n \"[\" ...\r\n \"{\" ...\r\n <NUMBER> ...\r\n ]; nested: ParseException[Encountered \" \"-\" \"- \"\" at line 1, column 4.\r\nWas expecting one of:\r\n <BAREOPER> ...\r\n \"(\" ...\r\n \"*\" ...\r\n <QUOTED> ...\r\n <TERM> ...\r\n <PREFIXTERM> ...\r\n <WILDTERM> ...\r\n <REGEXPTERM> ...\r\n \"[\" ...\r\n \"{\" ...\r\n <NUMBER> ...\r\n ]; }{[NfwFTkfwTAuyO6QGG9hUUw][cazv][1]: SearchParseException[[cazv][1]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"query_string\":{\"query\":\"_id:-yTCu-HxSkOhwDOp4JVblg\",\"lowercase_expanded_terms\":true,\"analyze_wildcard\":false}}}]]]; nested: QueryParsingException[[cazv] Failed to parse query [_id:-yTCu-HxSkOhwDOp4JVblg]]; nested: ParseException[Cannot parse '_id:-yTCu-HxSkOhwDOp4JVblg': Encountered \" \"-\" \"- \"\" at line 1, column 4.\r\nWas expecting one of:\r\n <BAREOPER> ...\r\n \"(\" ...\r\n \"*\" ...\r\n <QUOTED> ...\r\n <TERM> ...\r\n <PREFIXTERM> ...\r\n <WILDTERM> ...\r\n <REGEXPTERM> ...\r\n \"[\" ...\r\n \"{\" ...\r\n <NUMBER> ...\r\n ]; nested: ParseException[Encountered \" \"-\" \"- \"\" at line 1, column 4.\r\nWas expecting one of:\r\n <BAREOPER> ...\r\n \"(\" ...\r\n \"*\" ...\r\n <QUOTED> ...\r\n <TERM> ...\r\n <PREFIXTERM> ...\r\n <WILDTERM> ...\r\n <REGEXPTERM> ...\r\n \"[\" ...\r\n \"{\" ...\r\n <NUMBER> ...\r\n ]; }{[NfwFTkfwTAuyO6QGG9hUUw][cazv][2]: SearchParseException[[cazv][2]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"query_string\":{\"query\":\"_id:-yTCu-HxSkOhwDOp4JVblg\",\"lowercase_expanded_terms\":true,\"analyze_wildcard\":false}}}]]]; nested: QueryParsingException[[cazv] Failed to parse query [_id:-yTCu-HxSkOhwDOp4JVblg]]; nested: ParseException[Cannot parse '_id:-yTCu-HxSkOhwDOp4JVblg': Encountered \" \"-\" \"- \"\" at line 1, column 4.\r\nWas expecting one of:\r\n <BAREOPER> ...\r\n \"(\" ...\r\n \"*\" ...\r\n <QUOTED> ...\r\n <TERM> ...\r\n <PREFIXTERM> ...\r\n <WILDTERM> ...\r\n <REGEXPTERM> ...\r\n \"[\" ...\r\n \"{\" ...\r\n <NUMBER> ...\r\n ]; nested: ParseException[Encountered \" \"-\" \"- \"\" at line 1, column 4.\r\nWas expecting one of:\r\n <BAREOPER> ...\r\n \"(\" ...\r\n \"*\" ...\r\n <QUOTED> ...\r\n <TERM> ...\r\n <PREFIXTERM> ...\r\n <WILDTERM> ...\r\n <REGEXPTERM> ...\r\n \"[\" ...\r\n \"{\" ...\r\n <NUMBER> ...\r\n ]; }{[NfwFTkfwTAuyO6QGG9hUUw][cazv][3]: SearchParseException[[cazv][3]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"query_string\":{\"query\":\"_id:-yTCu-HxSkOhwDOp4JVblg\",\"lowercase_expanded_terms\":true,\"analyze_wildcard\":false}}}]]]; nested: QueryParsingException[[cazv] Failed to parse query [_id:-yTCu-HxSkOhwDOp4JVblg]]; nested: ParseException[Cannot parse '_id:-yTCu-HxSkOhwDOp4JVblg': Encountered \" \"-\" \"- \"\" at line 1, column 4.\r\nWas expecting one of:\r\n <BAREOPER> ...\r\n \"(\" ...\r\n \"*\" ...\r\n <QUOTED> ...\r\n <TERM> ...\r\n <PREFIXTERM> ...\r\n <WILDTERM> ...\r\n <REGEXPTERM> ...\r\n \"[\" ...\r\n \"{\" ...\r\n <NUMBER> ...\r\n ]; nested: ParseException[Encountered \" \"-\" \"- \"\" at line 1, column 4.\r\nWas expecting one of:\r\n <BAREOPER> ...\r\n \"(\" ...\r\n \"*\" ...\r\n <QUOTED> ...\r\n <TERM> ...\r\n <PREFIXTERM> ...\r\n <WILDTERM> ...\r\n <REGEXPTERM> ...\r\n \"[\" ...\r\n \"{\" ...\r\n <NUMBER> ...\r\n ]; }{[NfwFTkfwTAuyO6QGG9hUUw][cazv][4]: SearchParseException[[cazv][4]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"query_string\":{\"query\":\"_id:-yTCu-HxSkOhwDOp4JVblg\",\"lowercase_expanded_terms\":true,\"analyze_wildcard\":false}}}]]]; nested: QueryParsingException[[cazv] Failed to parse query [_id:-yTCu-HxSkOhwDOp4JVblg]]; nested: ParseException[Cannot parse '_id:-yTCu-HxSkOhwDOp4JVblg': Encountered \" \"-\" \"- \"\" at line 1, column 4.\r\nWas expecting one of:\r\n <BAREOPER> ...\r\n \"(\" ...\r\n \"*\" ...\r\n <QUOTED> ...\r\n <TERM> ...\r\n <PREFIXTERM> ...\r\n <WILDTERM> ...\r\n <REGEXPTERM> ...\r\n \"[\" ...\r\n \"{\" ...\r\n <NUMBER> ...\r\n ]; nested: ParseException[Encountered \" \"-\" \"- \"\" at line 1, column 4.\r\nWas expecting one of:\r\n <BAREOPER> ...\r\n \"(\" ...\r\n \"*\" ...\r\n <QUOTED> ...\r\n <TERM> ...\r\n <PREFIXTERM> ...\r\n <WILDTERM> ...\r\n <REGEXPTERM> ...\r\n \"[\" ...\r\n \"{\" ...\r\n <NUMBER> ...\r\n ]; }]",
"status" : 400
}
答案 0 :(得分:2)
您正在使用查询解析器,它将-
解释为NOT前缀运算符,我个人认为它是第二个 - 它让人感到困惑。您可能想在术语周围加上引号,或者只在id字段上使用术语查询,或者只是将其放在网址/index/type/id
西蒙
答案 1 :(得分:0)
我有类似的问题,所以我使用映射来覆盖我的ProductId的_id。 在你的情况下,将_id设置为volumeId,但我不知道你的volumeId是否是唯一的。
映射:
{
"issue" : {
"_id" : {
"path" : "volumeId"
}
}
映射后:
..., {
"_index" : "cazv",
"_type" : "issue",
"_id" : "At8YmsUdRqmqX-OUJKvdcQ",
"_score" : 1.0,
"_source":{"volumeId": "At8YmsUdRqmqX-OUJKvdcQ","number": "No. 3"}
}, {
"_index" : "cazv",
"_type" : "issue",
"_id" : "Z97A5vG8TOSl7Bv0UlFGYg",
"_score" : 1.0,
"_source":{"volumeId": "Z97A5vG8TOSl7Bv0UlFGYg","number": "No. 1"}
}
我希望有所帮助。