Query with wildcard

I want to generate phrase queries with wildcard, but this query returns 0 result:

  "query": {
    "bool": {
      "must": [
        {
          "query_string": {
            "query": "\"user login authen*\"",
            "fields": [
              "text"
            ],
            "phrase_slop": 5,
            "default_operator": "and",
            "analyze_wildcard": true,
            "auto_generate_synonyms_phrase_query": false
          }
        }
      ]
    }
  }

Does phrase query handle wildcard (?*)? May I have an explication?

Someone proposed to use span queries for the queries with a proximity and wildcards. If we search with a long sentence, the query becomes too complexe.

I met another problem with span query, if I replace the search field "text.exact" (without stemming) by "text" (a filed with stemming) in the query below, I get 0 result. Why?

"query": {
    "span_near": {
      "clauses": [
        {
          "span_term": {"text.exact": "user"}
        },
        {
          "span_term": {"text.exact": "login"}
        },
        {
          "span_multi": {
            "match": {
              "wildcard": {"text.exact": "authen*"}
            }
          }
        }
      ],
      "slop": 5,
      "in_order": true
    }
  }

Another approach that may be of interest is to use the wildcard field.

Check the decision flowchart at the end of this blog before using though: Find strings within strings faster with the Elasticsearch wildcard field | Elastic Blog

Thank you for the proposition.

I tested the wildcard field, but it's not for our use case, we want to tokenize the text field and search with a proximity.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.