# Wildcard match on multiple fields

**URL:** <https://discuss.elastic.co/t/wildcard-match-on-multiple-fields/273852>\
**Category:** Elasticsearch\
**Created:** [May 24, 2021, 5:14pm UTC](https://discuss.elastic.co/t/wildcard-match-on-multiple-fields/273852 "2021-05-24T17:14:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rammi22](https://avatars.discourse-cdn.com/v4/letter/r/258eb7/32.png) [@Rammi22](https://discuss.elastic.co/u/Rammi22)\
**Post date:** [May 24, 2021, 5:14pm UTC](https://discuss.elastic.co/t/wildcard-match-on-multiple-fields/273852/1 "2021-05-24T17:14:33Z")

</div>

Hi,

im looking for the right query to find in multiple fields a wildcard query (phone number in phone number fields).

i use

- [ElasticsearchDSL](https://github.com/ongr-io/ElasticsearchDSL)
- [ElasticsearchPHP](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html)

I try the [Multi-match query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html) _with a part of given value_, that returns 0 results.

The query **as filter** with wildcard **with _complete number_** (_123456789_)  
=\> returns **8 records**

```auto
object(ONGR\ElasticsearchDSL\Query\Compound\BoolQuery)#1663 (2) {
  ["container":"ONGR\ElasticsearchDSL\Query\Compound\BoolQuery":private]=>
  array(1) {
    ["must"]=>
    array(1) {
      ["090632fe877364ef496234f6fc15d3f810b1f6e7a8ee71603345654778ec"]=>
      object(ONGR\ElasticsearchDSL\Query\FullText\MultiMatchQuery)#1657 (3) {
        ["fields":"ONGR\ElasticsearchDSL\Query\FullText\MultiMatchQuery":private]=>
        array(4) {
          [0]=>
          string(29) "data.detail.clientPhoneNumber"
          [1]=>
          string(32) "data.detail.mpServicePhoneNumber"
          [2]=>
          string(18) "data.detail.msisdn"
          [3]=>
          string(24) "data.detail.securecaller"
        }
        ["query":"ONGR\ElasticsearchDSL\Query\FullText\MultiMatchQuery":private]=>
        string(12) "*123456789*"
        ["parameters":"ONGR\ElasticsearchDSL\Query\FullText\MultiMatchQuery":private]=>
        array(0) {
        }
      }
    }
  }
  ["parameters":"ONGR\ElasticsearchDSL\Query\Compound\BoolQuery":private]=>
  array(0) {
  }
}

```

=\> result 8 records

The query **as filter** with wildcard **with _INcomplete number_** (_3456789_)  
=\> returns **0 records**

```auto
...
        ["query":"ONGR\ElasticsearchDSL\Query\FullText\MultiMatchQuery":private]=>
        string(12) "*3456789*"
...

```

Seems the `multimatch query` is [not the right one](https://discuss.elastic.co/t/query-with-multimatch-and-wildcard/189962/2). Maybe i misunderstand the purpose of this query.

So, anyone can help me out?

---

<div class="post-metadata">

**Author:** ![Rammi22](https://avatars.discourse-cdn.com/v4/letter/r/258eb7/32.png) [@Rammi22](https://discuss.elastic.co/u/Rammi22)\
**Post date:** [May 25, 2021, 5:52am UTC](https://discuss.elastic.co/t/wildcard-match-on-multiple-fields/273852/2 "2021-05-25T05:52:43Z")

</div>

Hi,

even `BoolQuery::SHOULD` does not match any hits.

I can't find out, which query or filter are the appropriative....

---

<div class="post-metadata">

**Author:** ![Rammi22](https://avatars.discourse-cdn.com/v4/letter/r/258eb7/32.png) [@Rammi22](https://discuss.elastic.co/u/Rammi22)\
**Post date:** [May 25, 2021, 7:11am UTC](https://discuss.elastic.co/t/wildcard-match-on-multiple-fields/273852/3 "2021-05-25T07:11:03Z")

</div>

i try to rephrase the question for better illustration:

There are nth documents stored in the es server, like:

```auto
- document #1 
field
   id: 1
   a:'testing'
   b:'i am a tester'
   c:'nothing here'
   d:1
- document #2 
field
   id: 2
   a:'test'
   b:'test'
   c:'test'
   d:2
- document #3 
field
   id:3	
   a:'no action'
   b:'this is a test'
   c:'nothing here'
   d:1
- ...

```

My **query** (fantasy code):  
`find records WHERE field.a="*test*" OR field.b="*test*" OR field.c="*test*" AND field.d=1;`

**Expected result**

| id | a | b | c | d |
| --- | --- | --- | --- | --- |
| 1 | **test** ing | i am a **test** er | nothing here | 1 |
| 3 | no action | this is a **test** | nothing here | 1 |

The part `WHERE field.a="*test*" OR field.b="*test*" OR field.c="*test*"` is done by using the `WildcardQuery` with `BoolQuery::SHOULD`:

```auto
$query = new DSLQuery\TermLevel\WildcardQuery('field.a','*test*');
// $searchInstance => new ONGR\ElasticsearchDSL\Client();
$searchInstance->addQuery($query, BoolQuery::SHOULD);

$query = new DSLQuery\TermLevel\WildcardQuery('field.b','*test*');
// $searchInstance => new ONGR\ElasticsearchDSL\Client();
$searchInstance->addQuery($query, BoolQuery::SHOULD);

$query = new DSLQuery\TermLevel\WildcardQuery('field.c','*test*');
// $searchInstance => new ONGR\ElasticsearchDSL\Client();
$searchInstance->addQuery($query, BoolQuery::SHOULD);  

```

But how to assign the `AND field.d=1` to the query?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 22, 2021, 7:11am UTC](https://discuss.elastic.co/t/wildcard-match-on-multiple-fields/273852/4 "2021-06-22T07:11:04Z")

</div>

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