【问题标题】:Elasticsearch custom analyzer issueElasticsearch 自定义分析器问题
【发布时间】:2019-11-04 17:54:32
【问题描述】:

我们必须重新创建 registry_promotion_condition 索引器,该索引器具有名为 custom_value_analyzer 的自定义分析器。因为分析器不是由索引器配置的,所以我们通过 api 调用应用了它。

POST /registry_promotion_condition/_close
PUT /registry_promotion_condition/_settings
{
  "analysis" : {
          "analyzer" : {
            "condition_value_analyzer" : {
              "type" : "custom",
              "tokenizer" : "punctuation"
            }
          },
          "tokenizer" : {
            "punctuation" : {
              "pattern" : ",",
              "type" : "pattern"
            }
          }
        }
}
POST /registry_promotion_condition/_open

在 dev 和 staging 中应用此分析器后,我们可以使用以下 api 调用毫无问题地获取数据。

POST /registry_promotion_condition/promotion_conditions/_search
{
  "from": 0,
  "size": 10,
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "promotionDisplayStatus": {
              "value": true,
              "boost": 1
            }
          }
        },
        {
          "match_phrase": {
            "conditionValue": {
              "query": 4242560,
              "analyzer": "condition_value_analyzer",
              "slop": 0,
              "zero_terms_query": "NONE",
              "boost": 0.8
            }
          }
        }
      ],
      "adjust_pure_negative": true,
      "boost": 1
    }
  },
  "sort": [
    {
      "promotionId": {
        "order": "asc"
      }
    }
  ]
}



但在现场它不会给出空洞的回应。你知道为什么会这样吗?是否有任何配置允许自定义分析器

这是我在现场环境中的映射

{
  "registry_promotion_condition" : {
    "mappings" : {
      "promotion_conditions" : {
        "properties" : {
          "conditionDataType" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "conditionEntityFieldId" : {
            "type" : "long"
          },
          "conditionId" : {
            "type" : "long"
          },
          "conditionStatus" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "conditionValue" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "conditionVersion" : {
            "type" : "long"
          },
          "createYear" : {
            "type" : "long"
          },
          "promotionActiveFrom" : {
            "type" : "date"
          },
          "promotionActiveUntil" : {
            "type" : "date"
          },
          "promotionCode" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "promotionCreatedAt" : {
            "type" : "date"
          },
          "promotionDescription" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "promotionDiscountAmount" : {
            "type" : "float"
          },
          "promotionDiscountType" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "promotionDisplayName" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "promotionDisplayStatus" : {
            "type" : "boolean"
          },
          "promotionId" : {
            "type" : "long"
          },
          "promotionMaxDiscountAmount" : {
            "type" : "float"
          },
          "promotionName" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "promotionRuleFile" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "promotionServiceType" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "promotionStatus" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "promotionType" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "promotionVersion" : {
            "type" : "long"
          },
          "routingKey" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          }
        }
      }
    }
  }
}

【问题讨论】:

  • “现场直播”是什么意思?请发布您的映射和示例。
  • 我们有三个环境 dev,stage,live live mean production
  • 您是否在更新分析仪后重新索引数据?
  • 是的,两种方法我都试过了。首先将分析器应用于已索引的数据,然后以两种方式设置分析器并重新索引它不起作用
  • 你能分享你的映射吗?

标签: elasticsearch analyzer


【解决方案1】:

尝试从以下位置更改您的映射:

 {
  "registry_promotion_condition" : {
    "mappings" : {
      "promotion_conditions" : {
        "properties" : {
          "conditionDataType" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "conditionEntityFieldId" : {
            "type" : "long"
          },
          "conditionId" : {
            "type" : "long"
          },
          "conditionStatus" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "conditionValue" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "conditionVersion" : {
            "type" : "long"
          },
          "createYear" : {
            "type" : "long"
          },
          "promotionActiveFrom" : {
            "type" : "date"
          },
          "promotionActiveUntil" : {
            "type" : "date"
          },
          "promotionCode" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "promotionCreatedAt" : {
            "type" : "date"
          },
          "promotionDescription" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "promotionDiscountAmount" : {
            "type" : "float"
          },
          "promotionDiscountType" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "promotionDisplayName" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "promotionDisplayStatus" : {
            "type" : "boolean"
          },
          "promotionId" : {
            "type" : "long"
          },
          "promotionMaxDiscountAmount" : {
            "type" : "float"
          },
          "promotionName" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "promotionRuleFile" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "promotionServiceType" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "promotionStatus" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "promotionType" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "promotionVersion" : {
            "type" : "long"
          },
          "routingKey" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          }
        }
      }
    }
  }
}

至(将分析器添加到您的 conditionValue 字段):

 {
  "registry_promotion_condition" : {
    "mappings" : {
      "promotion_conditions" : {
        "properties" : {
          "conditionDataType" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "conditionEntityFieldId" : {
            "type" : "long"
          },
          "conditionId" : {
            "type" : "long"
          },
          "conditionStatus" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "conditionValue" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            },
            "analyzer":"condition_value_analyzer"
          },
          "conditionVersion" : {
            "type" : "long"
          },
          "createYear" : {
            "type" : "long"
          },
          "promotionActiveFrom" : {
            "type" : "date"
          },
          "promotionActiveUntil" : {
            "type" : "date"
          },
          "promotionCode" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "promotionCreatedAt" : {
            "type" : "date"
          },
          "promotionDescription" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "promotionDiscountAmount" : {
            "type" : "float"
          },
          "promotionDiscountType" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "promotionDisplayName" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "promotionDisplayStatus" : {
            "type" : "boolean"
          },
          "promotionId" : {
            "type" : "long"
          },
          "promotionMaxDiscountAmount" : {
            "type" : "float"
          },
          "promotionName" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "promotionRuleFile" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "promotionServiceType" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "promotionStatus" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "promotionType" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "promotionVersion" : {
            "type" : "long"
          },
          "routingKey" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          }
        }
      }
    }
  }
}

您必须删除索引才能更新映射并再次重新索引。请参阅我的 answer 关于重新索引。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-08
    • 2016-01-12
    • 2014-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多