# Matching Token Subsets

**URL:** <https://discuss.elastic.co/t/matching-token-subsets/10404>\
**Category:** Elasticsearch\
**Created:** [January 18, 2013, 9:10am UTC](https://discuss.elastic.co/t/matching-token-subsets/10404 "2013-01-18T09:10:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![govind201](https://avatars.discourse-cdn.com/v4/letter/g/8dc957/32.png) [@govind201](https://discuss.elastic.co/u/govind201)\
**Post date:** [January 18, 2013, 9:10am UTC](https://discuss.elastic.co/t/matching-token-subsets/10404/1 "2013-01-18T09:10:49Z")

</div>

I'm trying to write a query that satisfies the following scenario:

- 
- 

_Query_: Apple iPhone 4S

_Documents_:

Apple iPhone 5 [SHOULD NOT MATCH]

4S iPhone [SHOULD MATCH]

Two documents should match if either contains all of the other words/tokens  
contained in the other. So in this case, all of the tokens of "4S iPhone"  
("4S" and "iPhone") are contained in "Apple iPhone 4S" ("Apple", "iPhone"  
and "4S"). But "Apple iPhone 4S" and "Apple iPhone 5" contain one token  
each ("4S" and "5" respectively) not present in the other. Any suggestions  
on how I can frame my query to satisfy this case?

Note, for the reverse scenario, where the query is "4S iPhone" and "iPhone  
4S by Apple" is a field in a document, a _match_ query (using standardard  
tokenizer) with default operator _AND_ works. I'm finding it more difficult  
when the document field itself is made up of fewer tokens than the query.

Thanks in advance!

--

---

<div class="post-metadata">

**Author:** ![dewadkar](https://avatars.discourse-cdn.com/v4/letter/d/ea666f/32.png) [@dewadkar](https://discuss.elastic.co/u/dewadkar)\
**Post date:** [January 18, 2013, 9:36am UTC](https://discuss.elastic.co/t/matching-token-subsets/10404/2 "2013-01-18T09:36:27Z")

</div>

Query expansion will work some extent. In your short documents also you can  
make query part as optional and exact match. In above query expansion  
"apple" is organization and iphone is product and its product sub-types as  
version (here 4S and 5 ) will help to expand it.

On Fri, Jan 18, 2013 at 2:40 PM, Govind Chandrasekhar  
[govind201@gmail.com](mailto:govind201@gmail.com)wrote:

> I'm trying to write a query that satisfies the following scenario:
> 
> - 
> - 
> 
> _Query_: Apple iPhone 4S
> 
> _Documents_:
> 
> Apple iPhone 5 [SHOULD NOT MATCH]
> 
> 4S iPhone [SHOULD MATCH]
> 
> Two documents should match if either contains all of the other  
> words/tokens contained in the other. So in this case, all of the tokens of  
> "4S iPhone" ("4S" and "iPhone") are contained in "Apple iPhone 4S"  
> ("Apple", "iPhone" and "4S"). But "Apple iPhone 4S" and "Apple iPhone 5"  
> contain one token each ("4S" and "5" respectively) not present in the  
> other. Any suggestions on how I can frame my query to satisfy this case?
> 
> Note, for the reverse scenario, where the query is "4S iPhone" and "iPhone  
> 4S by Apple" is a field in a document, a _match_ query (using standardard  
> tokenizer) with default operator _AND_ works. I'm finding it more  
> difficult when the document field itself is made up of fewer tokens than  
> the query.
> 
> Thanks in advance!
> 
> --

--  
Mr. Dnyaneshwar Dewadkar  
Dept. of Information Technology

--

---

<div class="post-metadata">

**Author:** ![govind201](https://avatars.discourse-cdn.com/v4/letter/g/8dc957/32.png) [@govind201](https://discuss.elastic.co/u/govind201)\
**Post date:** [January 18, 2013, 6:32pm UTC](https://discuss.elastic.co/t/matching-token-subsets/10404/3 "2013-01-18T18:32:29Z")

</div>

Unfortunately, my data is unstructured. Labelling the different parts of  
the query at scale is not an option for me.

On Friday, January 18, 2013 1:36:27 AM UTC-8, DD wrote:

> Query expansion will work some extent. In your short documents also you  
> can make query part as optional and exact match. In above query expansion  
> "apple" is organization and iphone is product and its product sub-types as  
> version (here 4S and 5 ) will help to expand it.
> 
> On Fri, Jan 18, 2013 at 2:40 PM, Govind Chandrasekhar \<[govi...@gmail.com](mailto:govi...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > I'm trying to write a query that satisfies the following scenario:
> > 
> > - 
> > - 
> > 
> > _Query_: Apple iPhone 4S
> > 
> > _Documents_:
> > 
> > Apple iPhone 5 [SHOULD NOT MATCH]
> > 
> > 4S iPhone [SHOULD MATCH]
> > 
> > Two documents should match if either contains all of the other  
> > words/tokens contained in the other. So in this case, all of the tokens of  
> > "4S iPhone" ("4S" and "iPhone") are contained in "Apple iPhone 4S"  
> > ("Apple", "iPhone" and "4S"). But "Apple iPhone 4S" and "Apple iPhone 5"  
> > contain one token each ("4S" and "5" respectively) not present in the  
> > other. Any suggestions on how I can frame my query to satisfy this case?
> > 
> > Note, for the reverse scenario, where the query is "4S iPhone" and  
> > "iPhone 4S by Apple" is a field in a document, a _match_ query (using  
> > standardard tokenizer) with default operator _AND_ works. I'm finding it  
> > more difficult when the document field itself is made up of fewer tokens  
> > than the query.
> > 
> > Thanks in advance!
> > 
> > --
> 
> --  
> Mr. Dnyaneshwar Dewadkar  
> Dept. of Information Technology

--

---

<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:** [July 6, 2017, 2:55am UTC](https://discuss.elastic.co/t/matching-token-subsets/10404/4 "2017-07-06T02:55:41Z")

</div>


