Elasticsearch analizer working when created throw Springdata but failing when creating straight from Postman/curl

前端 未结 1 1310
生来不讨喜
生来不讨喜 2021-01-27 10:19

Goal: create Elasticsearch index aimed to be loaded with 10 million simple documents. Each document is basically \"Elastisearch id\", \"some company id\" and \"name\". Provide s

相关标签:
1条回答
  • 2021-01-27 10:40

    As you have not provided your search query which you are using in postman, also the mapping, which would help us to debug, if you are not using the right analyzer on the fields, you are using in your search query. Also adding sample documents and your actual and expected search results always help.

    Nvm, I added your mapping and showing below, how that using postman as well, you will get the correct results.

    Index def exactly same as yours

    {
        "settings": {
            "analysis": {
                "filter": {
                    "autocomplete_filter": {
                        "type": "edge_ngram",
                        "min_gram": 1,
                        "max_gram": 20
                    }
                },
                "analyzer": {
                    "autocomplete_search": {
                        "type": "custom",
                        "tokenizer": "standard",
                        "filter": [
                            "lowercase"
                        ]
                    },
                    "autocomplete_index": {
                        "type": "custom",
                        "tokenizer": "standard",
                        "filter": [
                            "lowercase",
                            "autocomplete_filter"
                        ]
                    }
                }
            }
        },
        "mappings": {
            "properties": {
                "name": {
                    "type": "text",
                    "analyzer": "autocomplete_index",
                    "search_analyzer": "autocomplete_search"
                }
            }
        }
    }
    

    Index sample docs

    {
        "name" : "opster"
    }
    
    {
        "name" : "jim c"
    }
    
    {
        "name" : "jimc"
    }
    
    {
        "name" : "foo"
    }
    

    Searching for partial words like ji brings both jim c and jimc docs

    {
        "query": {
            "match": {
                "name": {
                    "query": "ji"
                }
            }
        }
    }
    

    Result

      "hits": [
                {
                    "_index": "61158504",
                    "_type": "_doc",
                    "_id": "2",
                    "_score": 0.69263697,
                    "_source": {
                        "name": "jimc"
                    }
                },
                {
                    "_index": "61158504",
                    "_type": "_doc",
                    "_id": "1",
                    "_score": 0.6133945,
                    "_source": {
                        "name": "jim c"
                    }
                }
            ]
    

    Note:- You can also check this and this links for more information on autocomplete.

    0 讨论(0)
提交回复
热议问题