多个索引的衰减函数,其中可能不存在衰减字段名称

时间:2017-06-12 15:15:31

标签: elasticsearch

我正在尝试跨多个索引使用衰减函数。我遇到的问题是其中一些索引没有衰减函数使用的字段,所以我得到以下错误。

{"type":"parsing_exception","reason":"unknown field [start_date]","line":1,"col":0},{"type":"parsing_exception","reason":"unknown field [match_date]","line":1,"col":0}

我可以提供任何有用的其他信息。

文档显示我尝试使用了一个过滤器选项,但是在找不到该字段时它仍然会跳闸。

我正在使用弹性搜索的php风格。

'query' => [
                "function_score" => [
                    'query' => [
                        "bool" => [
                            "must" => [
                                "multi_match" => [
                                    "query" => $search,
                                    "fields" => [
                                        "match_web_name",
                                        "shooter_result_name",
                                        "name",
                                        "post_match_name",
                                        "club_name"
                                    ]
                                ]
                            ],
                            "should" => [
                                [
                                    "term" => [
                                        "private" => 0
                                    ],
                                ]
                            ]
                        ]
                    ],
                    "functions" => [
                        [
                            "filter" => [ "exists" => ["field" => "start_date"]],
                            "linear" => [
                                "start_date" => [
                                    "origin" => 'now',
                                    "scale" => $scale
                                ]
                            ]
                        ],

                        [
                            "filter" => [ "exists" => ["field" => "match_date"]],
                            "linear" => [
                                "match_date" => [
                                    "origin" => 'now',
                                    "scale" => $scale
                                ]
                            ]
                        ]
                    ]
                ]
            ]

以下是没有start_date

的索引的映射
  "club": {
"properties": {
  "zip": {
    "type": "text",
    "fields": {
      "raw": {
        "type": "keyword"
      }
    }
  },
  "website": {
    "type": "text",
    "fields": {
      "raw": {
        "type": "keyword"
      }
    }
  },
  "city": {
    "type": "text",
    "fields": {
      "en": {
        "analyzer": "english",
        "type": "text"
      },
      "raw": {
        "type": "keyword"
      }
    }
  },
  "about": {
    "type": "text",
    "fields": {
      "en": {
        "analyzer": "english",
        "type": "text"
      }
    }
  },
  "tagline": {
    "type": "text",
    "fields": {
      "en": {
        "analyzer": "english",
        "type": "text"
      }
    }
  },
  "location": {
    "ignore_malformed": true,
    "type": "geo_point"
  },
  "id": {
    "type": "integer"
  },
  "state": {
    "type": "text",
    "fields": {
      "en": {
        "analyzer": "english",
        "type": "text"
      },
      "raw": {
        "type": "keyword"
      }
    }
  },
  "club_name": {
    "type": "text",
    "fields": {
      "en": {
        "analyzer": "english",
        "type": "text"
      },
      "raw": {
        "type": "keyword"
      }
    }
  },
  "deleted_at": {
    "format": "yyyy-MM-dd HH:mm:ss",
    "type": "date"
  },
  "slug": {
    "type": "keyword"
  }
}

这是一个索引确实包含start_date

的映射
"match": {
"properties": {
  "end_date": {
    "null_value": "1990-01-01 12:12:12",
    "format": "yyyy-MM-dd HH:mm:ss",
    "type": "date"
  },
  "zip": {
    "type": "text",
    "fields": {
      "raw": {
        "type": "keyword"
      }
    }
  },
  "private": {
    "type": "boolean"
  },
  "reg_close_date": {
    "null_value": "1990-01-01 12:12:12",
    "format": "yyyy-MM-dd HH:mm:ss",
    "type": "date"
  },
  "city": {
    "type": "text",
    "fields": {
      "en": {
        "analyzer": "english",
        "type": "text"
      },
      "raw": {
        "type": "keyword"
      }
    }
  },
  "level": {
    "type": "keyword"
  },
  "description": {
    "type": "text",
    "fields": {
      "en": {
        "analyzer": "english",
        "type": "text"
      }
    }
  },
  "max_shooters": {
    "type": "integer"
  },
  "type": {
    "type": "keyword"
  },
  "deleted_at": {
    "format": "yyyy-MM-dd HH:mm:ss",
    "ignore_malformed": true,
    "type": "date"
  },
  "reg_open_date": {
    "null_value": "1990-01-01 12:12:12",
    "format": "yyyy-MM-dd HH:mm:ss",
    "type": "date"
  },
  "score_type": {
    "type": "keyword"
  },
  "club_id": {
    "type": "integer"
  },
  "match_web_name": {
    "type": "text",
    "fields": {
      "en": {
        "analyzer": "english",
        "type": "text"
      },
      "raw": {
        "type": "keyword"
      }
    }
  },
  "location": {
    "ignore_malformed": true,
    "type": "geo_point"
  },
  "id": {
    "type": "integer"
  },
  "state": {
    "type": "text",
    "fields": {
      "en": {
        "analyzer": "english",
        "type": "text"
      },
      "raw": {
        "type": "keyword"
      }
    }
  },
  "prices": {
    "type": "text",
    "fields": {
      "raw": {
        "type": "keyword"
      }
    }
  },
  "slug": {
    "type": "keyword"
  },
  "start_date": {
    "null_value": "1990-01-01 12:12:12",
    "format": "yyyy-MM-dd HH:mm:ss",
    "type": "date"
  },
  "status": {
    "type": "keyword"
  }
}

0 个答案:

没有答案