ElastiSeach Constant得分过滤器查询

时间:2016-12-22 11:21:55

标签: elasticsearch

我有ES 1.7映射,如下所示,

 PUT tagcloud_v3
{
  "mappings": {
    "_default_": {
      "_all": {
        "enabled": false
      },
      "_source": {
        "compressed": true
      },
      "properties": {
        "term": {
          "fields": {
            "raw": {
              "index": "not_analyzed",
              "analyzer": "lowercase_analyzer",
              "type": "string"
            }
          },
          "analyzer": "concat_all_alpha",
          "type": "string"
        },
        "relation": {
          "properties": {
            "term": {
              "type": "string",
              "analyzer": "concat_all_alpha",
              "fields": {
                "raw": {
                  "index": "not_analyzed",
                  "analyzer": "lowercase_analyzer",
                  "type": "string"
                }
              }
            },
            "weight": {
              "type": "double"
            },
            "updatedDate": {
              "index": "no",
              "type": "date"
            },
            "isActive": {
              "type": "boolean"
            },
            "rel": {
              "type": "string"
            },
            "source": {
              "index": "no",
              "type": "string"
            },
       "lastModifiedBy":{
        "index":"no",
        "type":"string"
        }
          }
        },
        "updatedDate": {
          "index": "no",
          "type": "date"
        },
        "isActive": {
          "type": "boolean"
        },
        "lastModifiedBy": {
          "index": "no",
          "type": "string"
        },
        "source": {
          "index": "no",
          "type": "string"
        }
      }
    }
  },
  "settings": {
    "index": {
      "analysis": {
        "analyzer": {
          "concat_all_alpha": {
            "char_filter": [
              "only_alphanum"
            ],
            "filter": [
              "lowercase"
            ],
            "tokenizer": "keyword"
          },
          "uppercase_analyzer": {
            "filter": "uppercase",
            "tokenizer": "keyword"
          },
          "lowercase_analyzer": {
            "filter": "lowercase",
            "tokenizer": "keyword"
          }
        },
        "char_filter": {
          "only_alphanum": {
            "pattern": "[^A-Z^a-z^0-9]|\\^",
            "replacement": "",
            "type": "pattern_replace"
          }
        }
      },
      "max_result_window": "1000000"
    }
  }
}

我们一次又一次地搜索同一个词。我们想为此使用ES过滤器缓存。我已经使用了constant_score搜索查询,(注意:对于任何搜索,我们只有一个结果/或无。)

GET tagcloud_v3/ITTEST/_search
    {
       "size": 1,
       "query": {
          "bool": {
             "should": [
                {
                   "bool": {
                      "must": [
                         {
                            "constant_score": {
                               "filter": {
                                  "term": {
                                     "term": "java"
                                  }
                               }
                            }
                         },
                         {
                            "constant_score": {
                               "filter": {
                                  "term": {
                                     "isActive": true
                                  }
                               }
                            }
                         }
                      ]
                   }
                },
                {
                   "bool": {
                      "must": {
                         "nested": {
                            "query": {
                               "bool": {
                                  "must": [
                                     {
                                        "constant_score": {
                                           "filter": {
                                              "term": {
                                                 "relation.term": "java"
                                              }
                                           }
                                        }
                                     },
                                     {
                                        "constant_score": {
                                           "filter": {
                                              "term": {
                                                 "relation.isActive": true
                                              }
                                           }
                                        }
                                     },
                                     {
                                        "constant_score": {
                                           "filter": {
                                              "term": {
                                                 "relation.rel": "S"
                                              }
                                           }
                                        }
                                     }
                                  ]
                               }
                            },
                            "path": "relation"
                         }
                      }
                   }
                }
             ]
          }
       }
    }

我的搜索查询是否正确?我们的ES映射是固定的。

0 个答案:

没有答案