has_parent无法在elasticsearch 1.3.0中使用过滤

时间:2014-09-15 18:21:02

标签: elasticsearch

elasticsearch 1.3.0 has_parent中,过滤在查询下无法正常工作。而另外它在 elasticsearch 1.3.0 中工作。此查询适用于旧的 elasticsearch 0.90.5 版本。

我正在使用以下查询。

{
   "from": 0,
   "size": 100,
   "query": {
      "has_parent": {
         "type": "url",
         "query": {
            "filtered": {
               "filter": {
                  "bool": {
                     "must_not": {
                        "terms": {
                           "affiliate_id": [
                              "1625024208"
                           ]
                        }
                     },
                     "must": {
                        "terms": {
                           "affiliate_id": [
                              "1718654495"
                           ]
                        }
                     }
                  }
               }
            }
         }
      },
      "filtered": {
         "filter": {
            "bool": {
               "must": {
                  "terms": {
                     "country": [
                        "India"
                     ]
                  }
               }
            }
         }
      }
   }
}

收到错误消息ElasticsearchParseException[Expected field name but got START_OBJECT "filtered"

完成错误消息:

SearchPhaseExecutionException[Failed to execute phase [query], all shards failed;
  shardFailures {[hZgYLUmsQL2T8z1MY2eyNA][esindex][5]: SearchParseException[[esindex][5]:
    query[parent_filter[url](filtered(affiliate_id:1718489511)->cache(_type:url))],from[-1],size[-1]:
    Parse Failure [Failed to parse source [
      {
        "query": {
          "has_parent": {
            "parent_type": "url",
            "query": {
              "match": {
                "affiliate_id": "1718489511"
              }
            }
          },
          "filtered": {
            "filter": {
              "bool": {
                "must": {
                  "terms": {
                    "country": [
                      "india"
                    ]
                  }
                }
              }
            }
          }
        }
      }
    ]]];
  nested: ElasticsearchParseException[Expected field name but got START_OBJECT "filtered"]; }{[OPG4zuQlQr2dFxUvRe2GWg][esindex][4]: 
  RemoteTransportException[[server1][inet[/127.0.0.1:9300]][search/phase/query]]; 
  nested: SearchParseException[[esindex][4]: 
    query[parent_filter[url](filtered(affiliate_id:1718489511)->cache(_type:url))],from[-1],size[-1]: 
    Parse Failure [Failed to parse source [
      {
        "query": {
          "has_parent": {
            "parent_type": "url",
            "query": {
              "match": {
                "affiliate_id": "1718489511"
              }
            }
          },
          "filtered": {
            "filter": {
              "bool": {
                "must": {
                  "terms": {
                    "country": [
                      "india"
                    ]
                  }
                }
              }
            }
          }
        }
      }
    ]]];
  nested: ElasticsearchParseException[Expected field name but got START_OBJECT "filtered"];

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

如果不在Elasticsearch 1.3.0上测试,我建议使用不同的查询:

{
  "query": {
    "has_parent": {
      "parent_type": "url",
      "query": {
        "filtered": {
          "filter": {
            "bool": {
              "must": {
                "terms": {
                  "country": [
                    "india"
                  ]
                }
              }
            }
          },
          "query": {
            "match": {
              "affiliate_id": "1718489511"
            }
          }
        }
      }
    }
  }
}

此查询符合您的解释,您想要做的事情:

  

在此查询中,我需要在has_parent中添加过滤,例如has_parent-> query-> filtered-> bool->必须

ES 0.90.x version

升级时,也许您应升级到较新的Bugfix-Release