3

In elasticsearch match_phrase query will match full phrase. match_phrase_prefix query will match phrase as prefix.
for example:

"my_field": "confidence ab" 

will match: "confidence above" and "confidence about".

is there query for "match phrase any" like below example:

"my_field": "dence ab" 

should fetch match: "confidence above" and "confidence about"

Thanks

Saeed Nasehi
  • 940
  • 1
  • 11
  • 27
V_R
  • 96
  • 9

3 Answers3

1

There are 2 ways that you can do this

  1. Store the field values as-is in ES by applying keyword analyzer type in mapping => Do a wildcard search (OR)
  2. Store the field using ngram tokenizer => Do search your data based on your requirement with or without using standard or keyword search analyzers

usually wildcard search are performance inefficient .

Please do let me know on your progress based on my above suggestions so that I can help you further if needed

0

You need to define the mapping of your field to keyword like below:

PUT test
{
  "mappings": {
    "properties": {
      "name":{
        "type": "keyword"
      }
    }
  }
}

Then search over this field using wildcard like below:

GET test/_search
{
  "query": {
    "wildcard": {
      "name": {
        "value": "*dence ab*"
      }
    }
  }
}

Please let me know if your have any problem with this.

Saeed Nasehi
  • 940
  • 1
  • 11
  • 27
0

In your case, the simplest solution is using Query string query or Simple query string query. The latter one is less strict with the query syntax error.

First, make sure that your field is mapped with type text. The example below create a mapping for field named my_field under the test-index.

{
  "test-index" : {
    "mappings" : {
      "properties" : {
        "my_field" : {
          "type" : "text"
        }
      }
    }
  }
}

Then, for searching, use query string query with wild-cards.

{
  "query": {
    "query_string": {
      "fields": ["my_field"], 
      "query": "*dence ab*"
    }
  }
}
Triet Doan
  • 11,455
  • 8
  • 36
  • 69