首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Elasticsearch 1.5有时不能过滤工作

Elasticsearch 1.5有时不能过滤工作
EN

Stack Overflow用户
提问于 2018-04-06 08:10:27
回答 2查看 61关注 0票数 0

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

代码语言:javascript
复制
"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
                      }
                    },...
EN

回答 2

Stack Overflow用户

发布于 2018-06-08 08:32:26

这最终成了索引的问题

代码语言:javascript
复制
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
EN

Stack Overflow用户

发布于 2018-04-10 03:56:54

然后,您应该像这样构造查询,即在顶级bool中移动must_not子句

代码语言:javascript
复制
"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
              }
         },...
      ]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49683366

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档