# Need suggestions on type of query to be used for a given analysis for better results?

**URL:** https://discuss.elastic.co/t/need-suggestions-on-type-of-query-to-be-used-for-a-given-analysis-for-better-results/17838
**Category:** Elasticsearch
**Created:** [May 30, 2014, 7:15pm UTC](https://discuss.elastic.co/t/need-suggestions-on-type-of-query-to-be-used-for-a-given-analysis-for-better-results/17838 "2014-05-30T19:15:21Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![dark\_shadow](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dark\_shadow](https://discuss.elastic.co/u/dark_shadow)
#### Post date: [May 30, 2014, 7:15pm UTC](https://discuss.elastic.co/t/need-suggestions-on-type-of-query-to-be-used-for-a-given-analysis-for-better-results/17838/1 "2014-05-30T19:15:21Z")

</div>

Hi,

I'm using following analyzers for indexing my documents in ES:

```
        "analysis" : {
           "analyzer" : {
              "str_search_analyzer" : {
                  "tokenizer" : "standard",
                  "filter" : ["lowercase","asciifolding"]
               },
               "str_index_analyzer" : {
                 "tokenizer" : "standard",
                 "filter" : ["lowercase","asciifolding","edgengram"]
             }
           },
           "filter" : {
              "edgengram" : {
                  "type" : "edgeNGram",
                  "min_gram" : 3,
                  "max_gram" : 20,
                  "side" : "front"
              }
          }
      }

```

I'm sure the search and index analyzers can serve my pupose well but  
querying documents in a right manner is also necessary for better results.  
I have read different queries which have been provided by ES but confused  
on which query or a combination of queries can work well with my use case.

Let's say I have a document which contains 3 fields:  
city\_name: Palo Alto  
state\_name: California  
country: United States

Now, my index analyzer will create following tokens on these 3 fields:  
city\_name: pal, palo, alt, alto  
state\_name: cal, cali, calif, califo, califor, californ, californi,  
california  
country: uni, unit, unite, united, sta, stat, state, states

And user search for a word like: palo alt  
now, my search analyzer will index it like: palo, alt

Now, I want to return only those documents which contains both these  
tokens, either in same field(like state, city or country) or as a  
combination of 2 fields. (Not those documents where either palo or pal or  
alt are present. )

Now which query can give me better results with these types of indexing and  
searching ?

I read about terms query but that works on not anlyzed fields. Also,  
querystring will generate some inbuilt regex queries for searching (I don't  
want that) I want only those documents where all the tokens of a user  
searched query are present in either same fields or multiple fields within  
same document. How can I achieve this ?

Any idea ?

Thanks

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/5e290988-db9f-4ba3-8273-f4172cd3ca3e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5e290988-db9f-4ba3-8273-f4172cd3ca3e%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![dark\_shadow](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dark\_shadow](https://discuss.elastic.co/u/dark_shadow)
#### Post date: [May 31, 2014, 5:19pm UTC](https://discuss.elastic.co/t/need-suggestions-on-type-of-query-to-be-used-for-a-given-analysis-for-better-results/17838/2 "2014-05-31T17:19:04Z")

</div>

I'll be thankful if someone can give me idea about this.

Thanks

On Saturday, 31 May 2014 00:45:21 UTC+5:30, coder wrote:

> Hi,
> 
> I'm using following analyzers for indexing my documents in ES:
> 
> ```
> "analysis" : {
> "analyzer" : {
> "str_search_analyzer" : {
> "tokenizer" : "standard",
> "filter" : ["lowercase","asciifolding"]
> },
> "str_index_analyzer" : {
> "tokenizer" : "standard",
> "filter" : ["lowercase","asciifolding","edgengram"]
> }
> },
> "filter" : {
> "edgengram" : {
> "type" : "edgeNGram",
> "min_gram" : 3,
> "max_gram" : 20,
> "side" : "front"
> }
> }
> }
> 
> ```
> 
> I'm sure the search and index analyzers can serve my pupose well but  
> querying documents in a right manner is also necessary for better results.  
> I have read different queries which have been provided by ES but confused  
> on which query or a combination of queries can work well with my use case.
> 
> Let's say I have a document which contains 3 fields:  
> city\_name: Palo Alto  
> state\_name: California  
> country: United States
> 
> Now, my index analyzer will create following tokens on these 3 fields:  
> city\_name: pal, palo, alt, alto  
> state\_name: cal, cali, calif, califo, califor, californ, californi,  
> california  
> country: uni, unit, unite, united, sta, stat, state, states
> 
> And user search for a word like: palo alt  
> now, my search analyzer will index it like: palo, alt
> 
> Now, I want to return only those documents which contains both these  
> tokens, either in same field(like state, city or country) or as a  
> combination of 2 fields. (Not those documents where either palo or pal or  
> alt are present. )
> 
> Now which query can give me better results with these types of indexing  
> and searching ?
> 
> I read about terms query but that works on not anlyzed fields. Also,  
> querystring will generate some inbuilt regex queries for searching (I don't  
> want that) I want only those documents where all the tokens of a user  
> searched query are present in either same fields or multiple fields within  
> same document. How can I achieve this ?
> 
> Any idea ?
> 
> Thanks

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/5764f7c8-88ee-4d17-8f18-c9df346a2e3f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5764f7c8-88ee-4d17-8f18-c9df346a2e3f%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:25am UTC](https://discuss.elastic.co/t/need-suggestions-on-type-of-query-to-be-used-for-a-given-analysis-for-better-results/17838/3 "2017-07-06T01:25:32Z")

</div>


