Elasticsearch: Find substring match

后端 未结 2 1250
一生所求
一生所求 2020-12-07 16:01

I want to perform both exact word match and partial word/substring match. For example if I search for \"men\'s shaver\" then I should be able to find \"men\'s shaver\" in th

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-07 16:17

    To search for partial field matches and exact matches, it will work better if you define the fields as "not analyzed" or as keywords (rather than text), then use a wildcard query.

    See also this.

    To use a wildcard query, append * on both ends of the string you are searching for:

    POST /my_index/my_type/_search
    {
    "query": {
        "wildcard": {
           "name": {
              "value": "*en's*"
           }
        }
    }
    }
    

    To use with case insensitivity, use a custom analyzer with a lowercase filter and keyword tokenizer.

    Custom Analyzer:

    "custom_analyzer": {
                "tokenizer": "keyword",
                "filter": ["lowercase"]
            }
    

    Make the search string lowercase

    If you get search string as AsD: change it to *asd*

提交回复
热议问题