Elasticsearch 1.5有时不能过滤工作

时间:2018-04-06 00:10:27

标签: elasticsearch

前几天我们注意到我们的must_not过滤器有时会起作用。在我的桌子上敲了几个小时后,我在这里。任何帮助,将不胜感激。此外,erpNumber术语最多可列出10k次。

"filter": {
    "bool": {
      "must": [
        {
          "term": {
            "websites": "c2c53320-98dc-4eca-8022-9efc00dea0dc"
          }
        },
        {
          "term": {
            "languageCode": "en-us"
          }
        },
        {
          "bool": {
            "must_not": [
              {
                "bool": {
                  "should": [
                    {
                      "term": {
                        "erpNumber": "LIP_LAGSMS" // this one doesn't get blocked
                      }
                    },
                    {
                      "term": {
                        "erpNumber": "LIP_LAGSRG" //this one does get blocked
                      }
                    },...

2 个答案:

答案 0 :(得分:1)

最终成为索引的问题

public override RootObjectMapping GetMapping()
{
    var productDefinition = base.GetMapping();
    var erpMapping = productDefinition.Properties.FirstOrDefault(o => o.Key.Name == nameof(ElasticsearchProduct.ErpNumber));
    productDefinition.Properties.Remove(erpMapping);
    productDefinition.Properties.Add(nameof(ElasticsearchProduct.ErpNumber).ToCamelCase(), new StringMapping { Index = FieldIndexOption.Analyzed, Analyzer = CustomAnalyzers.IscLowercaseAnalyzer });
    return productDefinition;
}

答案 1 :(得分:0)

然后你应该像这样构建你的查询,即移动顶级must_not中的bool子句:

"filter": {
    "bool": {
      "must": [
        {
          "term": {
            "websites": "c2c53320-98dc-4eca-8022-9efc00dea0dc"
          }
        },
        {
          "term": {
            "languageCode": "en-us"
          }
        }
      ],
      "must_not": [
         {
             "term": {
                "erpNumber": "LIP_LAGSMS" // this one doesn't get blocked
              }
         },
         {
              "term": {
                  "erpNumber": "LIP_LAGSRG" //this one does get blocked
              }
         },...
      ]