Defining analyzer while querying in elasticSearch

后端 未结 3 1872
眼角桃花
眼角桃花 2021-01-31 03:25

I am pretty new to elasticsearch and just need some clarification: Can we define a analyzer while querying the search server. I tried it with the \"text\" and \"field\" query an

相关标签:
3条回答
  • 2021-01-31 03:37

    The term, prefix, and wildcard queries expect the value specified in the query to be already analyzed.

    0 讨论(0)
  • 2021-01-31 03:37

    This syntax worked for me:

    GET /_search
    {
      "query": {
        "match_phrase": {
          "controller": {
            "analyzer": "keyword",
            "query": "api/v2/test"
          }
        }
      }
    }
    

    Find more details in the documentation.

    0 讨论(0)
  • 2021-01-31 03:49

    You can set a custom search-analyzer to be used for queries.

    From the docs:

    Usually, the same analyzer should be applied at index time and at search time, to ensure that the terms in the query are in the same format as the terms in the inverted index.

    Sometimes, though, it can make sense to use a different analyzer at search time, such as when using the analysis-edgengram-tokenizer for autocomplete.

    By default, queries will use the analyzer defined in the field mapping, but this can be overridden with the search_analyzer setting

    The docs also list an example. https://www.elastic.co/guide/en/elasticsearch/reference/current/search-analyzer.html

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