Wildcard match on multiple fields

Hi,

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

i use

I try the Multi-match query with a part of given value, that returns 0 results.

The query as filter with wildcard with complete number (123456789)
=> returns 8 records

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

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

Seems the multimatch query is not the right one. Maybe i misunderstand the purpose of this query.

So, anyone can help me out?

Hi,

even BoolQuery::SHOULD does not match any hits.

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

i try to rephrase the question for better illustration:

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

- 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 testing i am a tester 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:

$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?

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