gpt4 book ai didi

elasticsearch - 在Elasticsearch中以查询开始(不带短语)

转载 作者:行者123 更新时间:2023-12-03 00:04:02 25 4
gpt4 key购买 nike

以下是样本可用数据:

  • 租车服务
  • 机场租车
  • 机场接送汽车租赁
  • 租车服务
  • 汽车服务机场
  • 机场汽车服务
  • 城市汽车服务

  • 以下是我尝试过的查询:
  • 前缀,它使我们仅以+开头。
    就像如果我搜索机场的汽车,我们将不会得到类似“机场服务的汽车租赁”或机场接送汽车的租赁之类的结果。

    查询样例:
    "query": {
    "bool": {
    "must": [
    {
    "prefix": {
    "sfield.exact": {
    "value": "car hire"
    }
    }
    }
    ]
    }

  • 尝试了 match_phrase_prefix ,它也类似于前缀
  • 运行

    查询样例:
    "query": {
    "bool": {
    "must": [
    {
    "match_phrase_prefix": {
    "sfield": {
    "value": "car hire"
    }
    }
    }
    ]
    }
    }
  • 前缀和query_string 的组合,
    我尝试使用前缀匹配第一个单词,并使用query_string匹配其余单词(因为有时我还需要匹配部分匹配项,例如“car for air *”)。

  • 查询样例:
    "query": {
    "bool": {
    "must": [
    {
    "prefix": {
    "sfield.exact": {
    "value": "car "
    }
    }
    },
    {
    "query_string": {
    "default_field": "sfield",
    "query": "car hire*",
    "default_operator": "AND"
    }
    }
    ]
    }
    }

    Point 3效果很好,但是第一次执行需要很多时间。
    以前此查询返回的结果很快,但是现在响应缓慢。
    我将字段类型用作“文本”(用于query_string搜索)和“关键字”(用于前缀搜索),我的总数据大小约为60 GB,并且我的应用程序是使用PHP创建的。

    ,如果有什么方法可以在更短的时间内获取startwith +所有匹配的单词(包括部分匹配),请告诉我。.

    样本映射
    "mappings": {
    "ctype": {
    "_all": { "enabled": false },
    "properties": {
    "id": { "type": "long" },
    "cname": { "type": "text" },
    "sfield": {
    "type": "text",
    "fields": {
    "exact": {
    "type": "keyword"
    }
    }
    }
    }
    }
    }

    最佳答案

    如果我理解正确,则只需要start with选项。因此,我建议您使用wildcard:

    "query": {
    "bool": {
    "must": [
    {
    "wildcard": {
    "sfield.exact": "car hire*"
    }
    }
    ]
    }

    参见 Wildcard

    关于elasticsearch - 在Elasticsearch中以查询开始(不带短语),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46399291/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com