Match against stored wildcard string


(Fredrik Hörte) #1

I want to be able to match a given string against a field that contains a value where an asterix is a placeholder for any given value.

I have a string subdomain.domain-c.com and I want to return all documents that does not contain the exact match for subdomain.domain-c.com or the record *.domain-c.com. In the below example it should return Document 2. Is this possible?

Document 1

{
domains: [www.domain-a.com, domain-b.com, *.domain-c.com] 
}

Document 2

{
domains: [www.domain-a.com, domain-b.com] 
}

Document 3

{
domains: [subdomain.domain-c.com] 
}

(Christoph) #2

Hi Fredrik,

unfortunately I think it is not possible to use wildcards in field values and then match them against a concrete query, but I have some hints that might be useful towards a solution.

This blog post that explains how to use the path hierarchy tokenizer for domain names, so the parts of your domains will be stored in reverse order in the index. With this you might be able to use a match or prefix query in a must_not clause of a bool query to archieve what you are looking for.

I dont know about the exact use case you have, but maybe you can drop the wildcard in the subdomains and then do a negated search on the "domain-c.com" part using the reversed domain name? Not sure this completely solves your problem but maybe it helps.


(system) #3