首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >多个术语筛选器不起作用-弹性搜索

多个术语筛选器不起作用-弹性搜索
EN

Stack Overflow用户
提问于 2021-09-15 14:48:02
回答 1查看 42关注 0票数 0

我是DSL和im的新手,使用下面的json查询:

代码语言:javascript
复制
    {
  "from": 0,
  "min_score": 0.5,
  "query": {
    "bool": {
      "filter": [
        {
          "terms": {
            "extension": [
              "bmp",
              "jpg",
              "tif",
              "img",
              "png",
              "gif",
              "jpeg"
            ]
          }
        },
        {
          "terms": {
            "userContentType": [
              "webpage"
            ]
          }
        },
        {
          "terms": {
            "language": [
              "en",
              "gen"
            ]
          }
        },
        {
          "terms": {
            "metaLanguage": [
              "en"
            ]
          }
        }
      ],
      "should": [
        {
          "multi_match": {
            "fields": [
              "title",
              "description^5",
              "partNumber",
              "guid",
              "metaId",
              "keywords"
            ],
            "lenient": true,
            "query": "technology"
          }
        }
      ]
    }
  },
  "size": 50,
  "sort": [
    {
      "userContentType.keyword": {
        "order": "desc"
      }
    },
    {
      "_score": {
        "order": "desc"
      }
    }
  ]
}

但是我没有得到任何结果。但是,如果我去掉其中一个术语,说“extension”或“userContentType”,它就可以正常工作,并且我会得到预期的结果。我认为这与在过滤器中使用多个术语有关,但不确定为什么这也会导致问题。我试着去掉'should‘和'min_score’,但没有什么不同。

任何帮助都将不胜感激。

索引映射:

代码语言:javascript
复制
{
  "mappings": {
    "properties": {
      "Id": {
        "type": "long"
      },
      "applicationName": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "content": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "createdDate": {
        "type": "date"
      },
      "description": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "extension": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "industryCategoryIdentifiers": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "keywords": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "language": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "metaLanguage": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "pageId": {
        "type": "long"
      },
      "productLineCategoryIdentifiers": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "title": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "updatedDate": {
        "type": "date"
      },
      "url": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "userContentType": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      }
    }
  }
}
EN

回答 1

Stack Overflow用户

发布于 2021-09-15 15:40:45

根据您的映射,您需要使用keyword子字段,如下所示:

代码语言:javascript
复制
    {
      "terms": {
        "extension.keyword": [
          "bmp",
          "jpg",
          "tif",
          "img",
          "png",
          "gif",
          "jpeg"
        ]
      }
    },
    {
      "terms": {
        "userContentType.keyword": [
          "webpage"
        ]
      }
    },
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69195342

复制
相关文章

相似问题

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