Search Query for FTS Indexed string array field

Hi,

In my doc, I have a string array field

“DeliveryTargetCodes”: [
“web3__sections__1”,
“web3__sections__2”
],

In my FTS index, I added the child mapping for this field.

I tried both MatchQuery, MatchPhraseQuery to search for it, but it returned no results. Is there something I’m missing? Kindly help

new MatchPhraseQuery(“web3__sections__1”).Field(“DeliveryTargetCodes”)
new MatchQuery(“web3__sections__1”).Field(“DeliveryTargetCodes”)

Since DeliveryTargetCodes is an array of strings, you’ll need to index it as a child field.
Also, since the content has special characters and you’re searching for them as is - I would recommend using the “keyword” analyzer for it.

1 Like

Thanks @abhinav, it works.

I’m facing some trouble in writing the search query using .NET API. I’ve three questions (stated below).

  1. Implement GreaterThan in Datetime ( LastUpdatedOn >= “2020-08-01”)

new DateRangeQuery().Start(DateTime.Parse(“2020-08-01”), true).Field(“LastUpdatedOn”) → Throws an error on execution

  1. Match a number to an Id

new MatchQuery(“67”).Field(“Topics.Id”) → Not working when i pass a number as string

  1. IN clause implementation (DeliveryTargetCodes IN (‘web3__sections__international_asia’ , ‘web3__sections__citywire_global’ ))

new MatchPhraseQuery(“web3__sections__international_asia”).Field(“DeliveryTargetCodes”),
new MatchPhraseQuery(“web3__sections__citywire_global”).Field(“DeliveryTargetCodes”),

If both the matchphrasequery is added, it becomes an AND, I’m looking for OR implementation.

Kindly help.

I’ve included curl/http request examples, the documentation should help you build these queries in the right syntax for the SDKs.

  • For the greater than date range query, you’ll first need to index LastUpdatedOn as a “datetime” field. All formats compliant to ISO-8601 are accepted. Now your date time range query should resemble …
{"query":{"field": "LastUpdatedOn", "start":"2020-08-01", "inclusive_start": true}}
  • Next, match queries work on text only. So if “id” were indexed as a numeric field in the index definition, you would need to use a numeric range query even to do a point look up.
{"query":{"field": "Topics.id", "min": 67, "max": 67, "inclusive_min": true, "inclusive_max": true}}
  • To replicate the “IN” clause behavior, you’ll need to do a disjunction over 2 match queries - which effectively will get you the OR behavior you’re looking for …
{"query":{"disjuncts": [{"field": "DeliveryTargetCodes", "match": "web3___sections___international_asia"}, {"field": "DeliveryTargetCodes", "match": "web3___sections___citywire_global"}]}}
1 Like