我正在Elasticsearch上创建查询,以查找所有索引中的文档。
我需要在Elasticsearch上组合应该,必须和嵌套查询,我得到正确的结果,但是结果内部出现错误。
这是我正在使用的查询
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" }
}
}
]
}
}
这就是结果
{
"_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,
},
...
我没有写一些字段,因为代码太长了
答案 0 :(得分:2)
我是StackOverFlow的新手(让这个帐户回答这个问题:D),所以如果这个答案不合常理,请耐心等待。我最近一直在研究Elasticsearch中的嵌套字段,因此对如何出现此错误有一些想法。 您是否为文档类型定义了映射?如果您在映射中不告诉它,我认为Elasticsearch不会将该字段识别为嵌套字段:
PUT INDEX_NAME
{
"mappings": {
"DOC_TYPE": {
"properties": {
"entities": {"type": "nested"}
}
}
}
}
您可能必须为每种索引和文档类型指定此映射。不确定是否有一种方法可以处理一个请求。
我还注意到您有一个“ should”子句,其最小匹配项设置为1。我相信这与“ must”子句完全相同,因此我不确定这实现了什么目的(如果我错了,请纠正我)。如果指定了映射,则查询应如下所示:
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.../"
}
}
}
]
}
}
}