We are using the wildcard query to look for domains that are meeting the user provided input. E.g., when a user types in xyz they see a list of domains with xyz in it, this can be xyz.com, helloxyz.com, xyzworld.com, etc.
Furthermore, if the user inputs something with a period, our query will work _for the most part_, E.g., if the user input xyz1 elasticsearch will return xyz1.com, however, if the user input xyz1.com elasticsearch will NOT return xyz1.com.
So at first, we were led to believe that the wildcard query cannot support periods, however, upon further testing, we saw that was not the case. E.g., when a user types in xyz.com, we will get all domains with xyz.com like helloxyz.com and worldxyz.com.
We think elasticsearch has an issue with looking up a number followed up an escaped character.
Furthermore, we can't input dashes and find values with dashes in them, e.g., if we input xyz-goodbye we will not get xyz-domain.com.
So there is also the issue of characters like dashes.
We are using bodybuilder.js and our query is:
.query('wildcard', 'url', '*'+text+'*')
_.query('wildcard', 'url', '*xyz1.*') will not return xyz1.com_
Any help is highly appreciated, thank you.
Thank you for reporting the issue. Unfortunately, as I am not able to reproduce your issue, I don't think the problem is with Elasticsearch.
The problem can be with how you analyze your field (make sure it is a keyword) or with the tool you use for query (I am not familiar with bodybuilder.js - check how it escapes special symbols, test with simple http requests).
Here is an example that everything works for me:
Elasticsearch version 6.4.2
PUT test-index
{
"mappings": {
"_doc": {
"properties": {
"domain" : { "type" : "keyword"}
}
}
}
}
Wilcard with a number followed by dot
GET test-index/_search
{
"query": {
"wildcard": {"domain" : "*xyz1.*"}
}
}
results in:
{
"took": 2,
"timed_out": false,
"_shards": {...},
"hits": {
"total": 1,
"max_score": 1.0,
"hits": [
{
"_index": "test-index",
"_type": "_doc",
"_id": "8",
"_score": 1.0,
"_source": {
"domain": "xyz1.com"
}
}
]
}
}
Wilcard with dashes
GET test-index/_search
{
"query": {
"wildcard": {"domain" : "*xyz-goodbye*"}
}
}
results:
{
"took": 6,
"timed_out": false,
"_shards": {...},
"hits": {
"total": 1,
"max_score": 1.0,
"hits": [
{
"_index": "test-index",
"_type": "_doc",
"_id": "10",
"_score": 1.0,
"_source": {
"domain": "xyz-goodbye.com"
}
}
]
}
}
Closing issue, as this is not a problem with Elasticsearch
Thanks a lot for the help @mayya-sharipova ! Ok so there must be something wrong with my bodybuilder.js query, let me explore...
Hi @mayya-sharipova ok I am trying to use the standard elasticsearch.js library to make the query, unfortunately, it is still not working for me.
body: {
query: {
wildcard: {
url: '*vcse1.*'
}
}
},
What I am looking for elasticsearch to return is the domain
cl21vcse1.vtc.cdc.gov...
Also, I am running 6.2 on AWS in a t2.small.elasticsearch
Thank you for your help @mayya-sharipova ! Once I changed the mapping of the url from text to keyword it was working fine!
Hi @refayathaque ,
How/where did you change the mapping from text to keyword?
Most helpful comment
Thank you for your help @mayya-sharipova ! Once I changed the mapping of the url from
texttokeywordit was working fine!