【问题标题】:Elastic search - Search by alphabet characters A-Z弹性搜索 - 按字母字符 A-Z 搜索
【发布时间】:2018-08-01 10:49:05
【问题描述】:

我想问一下如何通过简单的1个字符A-Z

用弹性搜索过滤特定数据

所以..例如我得到了数据

  • 橙色
  • 苹果
  • 古代
  • 斧头

我想获取所有以字符开头(不包含)的结果,例如 "A"。所以结果是

  • 苹果
  • 古代
  • 斧头

我在这里发现我应该创建新的分析器 Analyzer_startswith 并像这样设置。做错了什么?现在我得到 0 个结果

Elastica .yml 配置

fos_elastica:
    clients:
        default: noImportantInfo
    indexes:
        bundleName:
            client: default
            finder: ~
            settings:
                index:
                    analysis:
                        analyzer:
                            analyzer_startswith:
                                type: custom
                                tokenizer: keyword
                                filter:
                                    - lowercase
            types:
                content:
                    properties:
                        id:
                            type: integer
                        elasticaPriority:
                            type: integer
                        title:
                            type: string
                            analyzer: another_custom_analyzer
                            fields:
                                raw:
                                    type: string
                                    index: not_analyzed
                        title_ngram:
                            type: string
                            analyzer: analyzer_startswith
                            property_path: title

谢谢

【问题讨论】:

    标签: elasticsearch doctrine-orm symfony-2.1


    【解决方案1】:

    您可以为此使用前缀查询,请参阅此处https://www.elastic.co/guide/en/elasticsearch/reference/5.5/query-dsl-prefix-query.html

    GET /_search
    { "query": {
        "prefix" : { "user" : "ki" }
       }
    }
    

    【讨论】:

      【解决方案2】:

      感谢我使用了前缀和它的工作原理。

      我将 index 设置为 not_analyzed 并使用 Prefix 查找字符串中的第一个字符。

      title_ngram:
         type: string
         property_path: title
         index: not_analyzed
      

      现在还有其他方法可以对我的 "title_ngram" 应用标准搜索吗?因为我想在 "title_ngram"

      中按单个 1 个字符进行搜索以及全文搜索

      【讨论】:

        【解决方案3】:

        试试这个

        GET /content/_search
        {
            "query": {
                "match": {
                    "title": "A"
                }
            },
            "sort": "title.raw"
        }
        

        更多信息请参考以下链接 https://www.elastic.co/guide/en/elasticsearch/guide/current/multi-fields.html

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-06-28
          • 1970-01-01
          • 2018-10-08
          • 1970-01-01
          • 2021-01-28
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多