我们必须重新创建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

在开发人员中使用此分析器并将其暂存后,我们可以使用以下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
              }
            }
          }
        }
      }
    }
  }
}

最佳答案

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

 {
  "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
              }
            }
          }
        }
      }
    }
  }
}

到(将分析器添加到您的条件值字段中):
 {
  "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

关于elasticsearch - Elasticsearch自定义分析器问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58688459/

10-15 19:06