gpt4 book ai didi

elasticsearch - ElasticSearch 中嵌套对象的通配符搜索

转载 作者:行者123 更新时间:2023-12-01 23:17:45 25 4
gpt4 key购买 nike

假设我们正在存储类型为 Vehicle 的对象,这些对象在以下结构中具有对类型所有者的引用。然后运行以下请求:

`POST:本地主机:9200/15/vehicles/_search'

具有以下主体:

 { "query": { "wildcard": {"make":"*toy*"} }}

返回相关对象:
     "took": 5,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "15.index",
"_type": "vehicle",
"_id": "352",
"_score": 1,
"_source": {
"id": "352",
"name": "toyota",
"owner_id": "12",
"owner": {
"id": "12",
"name": "John Smith",
"login_id": 1,
"active": true,
}
}
}
]
}

我现在正在尝试通过嵌套对象进行查询(例如属于用户 John Smith 的所有车辆)
 {"query": {"wildcard": {"owner.name": "*John*"}}}

不返回任何结果,而:
 {"query": {"wildcard": {"owner": {"name": "*John*"}}}}

错误:
  "error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {....
[4]: SearchParseException[....
Parse Failure [Failed to parse source [{ \"query\": { \"wildcard\": {\"owner\": {\"name\":\"*ab*\"} }}}]]]; nested: QueryParsingException[....
[wildcard] query does not support [name]]; }{....
[3]: SearchParseException[....
: Parse Failure [Failed to parse source [{ \"query\": { \"wildcard\": {\"owner\": {\"name\":\"*ab*\"} }}}]]]; nested: QueryParsingException[....
[wildcard] query does not support [name]]; }{....
[2]: SearchParseException[....
]: Parse Failure [Failed to parse source [{ \"query\": { \"wildcard\": {\"owner\": {\"name\":\"*ab*\"} }}}]]]; nested: QueryParsingException[....
[wildcard] query does not support [name]]; }{....
: SearchParseException[[....
: Parse Failure [Failed to parse source [{ \"query\": { \"wildcard\": {\"owner\": {\"name\":\"*ab*\"} }}}]]]; nested: QueryParsingException[....
[wildcard] query does not support [name]]; }{....
[0]: SearchParseException[....: Parse Failure [Failed to parse source [{ \"query\": { \"wildcard\": {\"owner\": {\"name\":\"*ab*\"} }}}]]]; nested: QueryParsingException[.... [wildcard] query does not support [name]]; }]",
"status": 400

针对嵌套对象的查询(通配符或其他)的正确格式是什么?通配符查询与该模板有何不同(如果有的话)?

最佳答案

您需要使用 Nested Query查询 nested 内的字段类型。

{
"query":{
"nested":{
"path":"owner",
"query":{
"wildcard":{
"owner.name":"John*"
}
}
}
}
}

此外,您不应该以通配符开始您的术语,因为它会导致查询速度极慢。

如果您有多个级别的 nested反对 path值应该是 nested的最深层次对象,并且查询中的属性应该是完整路径。
{
"query":{
"nested":{
"path":"owner.pets",
"query":{
"wildcard":{
"owner.pets.name":"{someValue}"
}
}
}
}
}

关于elasticsearch - ElasticSearch 中嵌套对象的通配符搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25956371/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com