Giter VIP home page Giter VIP logo

Comments (5)

occultskyrong avatar occultskyrong commented on July 30, 2024 1

index如下:


{
    "index": {
        "analysis": {
            "analyzer": {
                "prefix_pinyin_analyzer": {
                    "tokenizer": "keyword",
                    "filter": ["lowercase", "prefix_pinyin"]
                }
                , "full_pinyin_analyzer": {
                    "tokenizer": "keyword",
                    "filter": ["lowercase", "full_pinyin"]
                }
            },
            "tokenizer": {
                "prefix_pinyin": {
                    "type": "pinyin",
                    "first_letter": "prefix",
                    "padding_char": ""
                }
            },
            "filter": {
                "_pattern": {
                    "type": "pattern_capture",
                    "preserve_original": 1,
                    "patterns": ["([0-9])", "([a-z])"]
                }
                , "prefix_pinyin": {
                    "type": "pinyin",
                    "first_letter": "prefix",
                    "padding_char": ""
                }
                , "full_pinyin": {
                    "type": "pinyin",
                    "first_letter": "none",
                    "padding_char": ""
                }
            }
        }
    }
}

mapping设置:

          "name_prefix_pinyin": {
                "type": "completion",
                "analyzer": "prefix_pinyin_analyzer",
                "search_analyzer": "prefix_pinyin_analyzer",
                "preserve_separators": false,
                "payloads": true
            },
            "name_full_pinyin": {
                "type": "completion",
                "analyzer": "full_pinyin_analyzer",
                "search_analyzer": "full_pinyin_analyzer",
                "preserve_separators": false,
                "payloads": true
            },

然后用suggester去搜对应内容,此部分涉及到业务,可能不同

, body: {
            goods_prefix_suggest: {
                text: '',#搜索的key
                completion: {
                       field:"name_prefix_pinyin" #搜索的字段
                       ,size:10 #搜索的长度
                }
            }
            , goods_full_suggest: {
                text: '',#搜索的key
                completion: {..} #同上 
            }
        }
``

from elasticsearch-analysis-pinyin.

brucebao avatar brucebao commented on July 30, 2024

目前Completion Suggest不支持(要命的前缀查询),用query解决吧

from elasticsearch-analysis-pinyin.

windcandle avatar windcandle commented on July 30, 2024

非常感谢!我试试!!

from elasticsearch-analysis-pinyin.

occultskyrong avatar occultskyrong commented on July 30, 2024

1、这是es2.3.4下。
2、因为我是nodejs,所以用的是Elasticsearch.js中的suggest()方法,你根据你自己后端语言自己看下
https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-suggest
3、使用这个completion suggester可以和context suggester结合使用来进行类似于query的match、term等过滤。
但是有个bug。。。。Deleted documents show up in completion suggester
我还没找到解决方法。。。。
当然,如果你的doc不需要update或者delete的话没啥问题。。。了吧。。

from elasticsearch-analysis-pinyin.

medcl avatar medcl commented on July 30, 2024

请参见最新的README文档,使用起来更加简单

from elasticsearch-analysis-pinyin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.