# Mapping for finding keywords in domains

**URL:** https://discuss.elastic.co/t/mapping-for-finding-keywords-in-domains/179267
**Category:** Elasticsearch
**Created:** [May 1, 2019, 11:28pm UTC](https://discuss.elastic.co/t/mapping-for-finding-keywords-in-domains/179267 "2019-05-01T23:28:30Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![hacker\_21](https://avatars.discourse-cdn.com/v4/letter/h/a6a055/32.png) [@hacker\_21](https://discuss.elastic.co/u/hacker_21)
#### Post date: [May 1, 2019, 11:28pm UTC](https://discuss.elastic.co/t/mapping-for-finding-keywords-in-domains/179267/1 "2019-05-01T23:28:31Z")

</div>

hi there,

I recently ran a search called "toronto dental" on google and noticed it even matches for keywords inside of domain names too:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/4/2/42651223973b1c2af32f9070c3c04ea60809c91f.png)

![image](https://us1.discourse-cdn.com/elastic/original/3X/0/a/0abd976ca769ed7334c9d4fc2d80580f373a4e38.png)

the domain is a single word, yet they are able to search for the two words (in any order) inside of the 2 domain results above.

I was just wondering if there is a similar mapping or querying approach that can accomplish this in Elasticsearch? Find keywords inside of a string with no spaces, and also find the words in any order as long as they are in the string.

Thanks and hope you guys are having a good week,

---

<div class="post-metadata">

### Author: ![hacker\_21](https://avatars.discourse-cdn.com/v4/letter/h/a6a055/32.png) [@hacker\_21](https://discuss.elastic.co/u/hacker_21)
#### Post date: [May 3, 2019, 2:48pm UTC](https://discuss.elastic.co/t/mapping-for-finding-keywords-in-domains/179267/2 "2019-05-03T14:48:07Z")

</div>

to clarify, if the search query is `toronto dental`:

is there a mapping which can find these 2 keywords inside a "domain" field with values like:  
`torontobeachdental.com` or `citydentaltoronto.com`

---

<div class="post-metadata">

### Author: ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)
#### Post date: [May 3, 2019, 3:12pm UTC](https://discuss.elastic.co/t/mapping-for-finding-keywords-in-domains/179267/3 "2019-05-03T15:12:03Z")

</div>

One approach is to use [Ngrams](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-ngram-tokenfilter.html) - that's choosing to index arbitrary length substrings within a string rather than just the whole thing.

It doesn't identify particular words but that can be ambiguous anyway as the registered domain holders of the pen store `PenIsland.com` and the actor-agent search service `WhoRepresents.com` found out.

---

<div class="post-metadata">

### Author: ![hacker\_21](https://avatars.discourse-cdn.com/v4/letter/h/a6a055/32.png) [@hacker\_21](https://discuss.elastic.co/u/hacker_21)
#### Post date: [May 11, 2019, 5:36pm UTC](https://discuss.elastic.co/t/mapping-for-finding-keywords-in-domains/179267/4 "2019-05-11T17:36:44Z")

</div>

haha thanks for sharing Mark.

I now have `min_gram` set to **1** and `max_gram` set to **1** as well on my `new_domain` field.

However, when I go into Kibana, I noticed the following:  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/f/3/f389ce803a94b0ea739a9a8b7c8c105d3dba1a09.png)  
this matches any doc where the new\_domain field has the letters D, E, N, T, A, or L ... which is almost my entire dataset

![image](https://us1.discourse-cdn.com/elastic/original/3X/5/0/505558396c205d92b2de9647972b82d37092baf0.png)  
this matches the "expected" way of looking across the new\_domain field values for docs where there is a sequence of D-E-N-T-A-L producing a correct amount.

The problem is when I'm using Elasticsearch DSL (python) to make a search, looking up "dental" or even "'dental'" as the query produces results like the first time in Kibana. Instead of looking for the sequence of letters, it's matching any documents with those letters.

Is there anything I can do? How can I query elasticsearch to look for the sequence in the new\_domain field? Thank you!

---

<div class="post-metadata">

### Author: ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)
#### Post date: [May 12, 2019, 8:07am UTC](https://discuss.elastic.co/t/mapping-for-finding-keywords-in-domains/179267/5 "2019-05-12T08:07:52Z")

</div>

> [@hacker\_21](#):
>
> Is there anything I can do?

Normally you’d use ngrams of 3 or more

---

<div class="post-metadata">

### Author: ![hacker\_21](https://avatars.discourse-cdn.com/v4/letter/h/a6a055/32.png) [@hacker\_21](https://discuss.elastic.co/u/hacker_21)
#### Post date: [May 13, 2019, 7:03pm UTC](https://discuss.elastic.co/t/mapping-for-finding-keywords-in-domains/179267/6 "2019-05-13T19:03:53Z")

</div>

But even in the above example, say with a mapping of 4, wouldn't it match "dent" with:  
[Dentureclinic.com](http://Dentureclinic.com)  
[Cardentwizard.com](http://Cardentwizard.com)

Or "tist" with:  
[Scientist.com](http://Scientist.com)  
[Cardentscientist.com](http://Cardentscientist.com)

As well?

---

<div class="post-metadata">

### Author: ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)
#### Post date: [May 13, 2019, 8:34pm UTC](https://discuss.elastic.co/t/mapping-for-finding-keywords-in-domains/179267/7 "2019-05-13T20:34:17Z")

</div>

Right, but if the search is “Toronto dental” then those urls that contain more of the ngrams than others will rank highest in results.  
The search engine rewards matches that contain more of the search terms than others and also ranks rarer terms highly (eg the ‘oro’ and ‘nto’ from Toronto)

---

<div class="post-metadata">

### Author: ![hacker\_21](https://avatars.discourse-cdn.com/v4/letter/h/a6a055/32.png) [@hacker\_21](https://discuss.elastic.co/u/hacker_21)
#### Post date: [May 15, 2019, 12:28am UTC](https://discuss.elastic.co/t/mapping-for-finding-keywords-in-domains/179267/8 "2019-05-15T00:28:41Z")

</div>

Thank you for clarifying Mark, I see what you're saying now. It has a "bigger picture" and multiple factors which end up creating the score, not just the domain.

What method of querying do you recommend? I have set minimum n-gram size to 3 and max to 7. Unfortunately, `match_phrase` for Toronto Dentist did not contribute to results (same overall score, same # of results) ... and a simple `match` is behaving oddly as well for the same query.

---

<div class="post-metadata">

### Author: ![hacker\_21](https://avatars.discourse-cdn.com/v4/letter/h/a6a055/32.png) [@hacker\_21](https://discuss.elastic.co/u/hacker_21)
#### Post date: [May 15, 2019, 3:40pm UTC](https://discuss.elastic.co/t/mapping-for-finding-keywords-in-domains/179267/9 "2019-05-15T15:40:33Z")

</div>

Just re-visited the various options available in the ES docs ...

Instead of a `match` or `math_phrase`, do you think a `term` query would be more suitable in this scenario?

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [June 12, 2019, 3:40pm UTC](https://discuss.elastic.co/t/mapping-for-finding-keywords-in-domains/179267/10 "2019-06-12T15:40:54Z")

</div>

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