Vit*_*ari 1 nested elasticsearch
我正在 Elasticsearch 上创建一个查询,用于通过所有索引查找文档。
我需要在 Elasticsearch 上结合 should、must 和嵌套查询,我得到了正确的结果,但在结果中出现了错误。
这是我正在使用的查询
GET _all/_search
{
"query": {
"bool": {
"minimum_should_match": 1,
"should": [
{ "term": { "trimmed_final_url": "https://www.repubblica.it/t.../" } }
],
"must": [
{
"nested": {
"path": "entities",
"query": {
"bool": {
"must": [
{ "term": { "entities.id": "138511" } }
]
}
}
}
},
{
"term": {
"language": { "value": "it" }
}
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
这就是结果
{
"_shards" : {
"total" : 38,
"successful" : 14,
"skipped" : 0,
"failed" : 24,
"failures" : [
{
"shard" : 0,
"index" : ".kibana_1",
"node" : "7twsq85TSK60LkY0UiuWzA",
"reason" : {
"type" : "query_shard_exception",
"reason" : """
failed to create query: {
...
"index_uuid" : "HoHi97QFSaSCp09iSKY1DQ",
"index" : ".reporting-2019.06.02",
"caused_by" : {
"type" : "illegal_state_exception",
"reason" : "[nested] failed to find nested object under path [entities]"
}
}
},
...
"hits" : {
"total" : {
"value" : 50,
"relation" : "eq"
},
"max_score" : 16.90015,
"hits" : [
{
"_index" : "i_201906_v1",
"_type" : "_doc",
"_id" : "MugcbmsBAzi8a0oJt96Q",
"_score" : 16.90015,
"_source" : {
"language" : "it",
"entities" : [
{
"id" : 101580,
},
{
"id" : 156822,
},
...
Run Code Online (Sandbox Code Playgroud)
有些字段我没写,因为代码太长了
小智 5
我是 StackOverFlow 的新手(创建这个帐户是为了回答这个问题:D)所以如果这个答案不合时宜,请耐心等待。我最近一直在探索 Elasticsearch 中的嵌套字段,所以我对如何出现此错误有一些想法。您是否为您的文档类型定义了映射?如果您没有在映射中告诉它这样做,我不相信 Elasticsearch 会将字段识别为嵌套:
PUT INDEX_NAME
{
"mappings": {
"DOC_TYPE": {
"properties": {
"entities": {"type": "nested"}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
您可能必须为每个索引和文档类型指定此映射。不确定是否有办法通过一个请求来完成所有操作。
我还注意到你有一个“应该”子句,最小匹配设置为 1。我相信这与“必须”子句完全相同,所以我不确定这达到了什么目的(如果我错了,请纠正我)。如果指定了映射,则查询应如下所示:
GET /_all/_search
{
"query": {
"bool": {
"must": [
{
"nested": {
"path": "entities",
"query": {
"term": {
"entities.id": {
"value": "138511"
}
}
}
}
},
{
"term": {
"language": {
"value": "it"
}
}
},
{
"term": {
"trimmed_final_url": {
"value": "https://www.repubblica.it/t.../"
}
}
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
783 次 |
| 最近记录: |