FTS index combine two fields

Hi,
In my json , I will have “phonenumber”:{“countrycode”:“1”, “phone”:“1234567890”} , I have used the alias field name and query using match with “operator”:“and” that works. but I have to do a wildcard {“wildcard”:“11234567890”}query on these field what would be the best way to do this ? . Thanks

I’m not sure I follow your question here - are you trying to combine values from 2 fields to see if it matches your wildcard?

Hi Abhinav, Thanks for the reply. yes I am looking for wildcard match on combined filed. (countryCode+phoneNumber) as a searchTerm.

Well, this is not really what we call a “wildcard” match. A wildcard is where we search for something similar but need not be identical.

Coming to your challenge here though - would a simple conjunction here not work for you?

{
  "query": {
    "conjuncts": [
      {"field": "countryCode", "match": "1"},
      {"field": "phone", "match": "1234567890"}
    ]
  }
}

Search indexes do now allow for concatenating fields within a document, so we’ll have to make it a query time approach.

I have two cases in my search 1.) search term is a full phone number 2.) The input could be a partial phone number(say 163156 or 63156).

I used the a similar approach like you mentioned for case 1 input is a phone number. (I used fullPhoneNumber as alias for the field countryCode and phone) This is working fine.
{
“query”: {
{“field”: “fullPhoneNumber”, “match”: “1 1234567890”, “operator”:“and”},
}
}
My question is what would be the best way to do a partial search on these terms ( my input can be with or without country code).

I see. Then I have 2 approaches I can recommend here, both involve indexing them as separate fields. So index countryCode as text field with keyword analyzer.

Now,

(1) Index phone as a text field with keyword analyzer and here’s a sample conjunction query showing wildcard usage -

{
  "query": {
    "conjuncts": [
      {"field": "countryCode", "term": "1"},
      {"field": "phone", "wildcard": "*567*"}
    ]
  }
}

(2) If you identify a minimum number of characters that your users can provide to search for the phone number, say 3 (for example) - you can define an ngram token filter and a custom analyzer over the field with - min:3, max:10. Here’s how that would look in your index definition -

{
  "analysis": {
    "char_filters": {},
    "tokenizers": {},
    "analyzers": {
      "custom_ngram": {
        "type": "custom",
        "char_filters": [],
        "tokenizer": "single",
        "token_filters": [
          "ngram_min_3_max_10"
        ]
      }
    },
    "token_filters": {
      "ngram_min_3_max_10": {
        "min": 3,
        "max": 10,
        "type": "ngram"
      }
    },
    "token_maps": {}
  }
}

And run the same query this way instead -

{
  "query": {
    "conjuncts": [
      {"field": "countryCode", "term": "1"},
      {"field": "phone", "term": "567"}
    ]
  }
}

Option (2) above would be faster during search, while (1) would be faster during indexing owing to when we’re doing the compute.