# I have a doubt at how to avoiding type gotchas

**URL:** <https://discuss.elastic.co/t/i-have-a-doubt-at-how-to-avoiding-type-gotchas/18893>\
**Category:** Elasticsearch\
**Created:** [July 25, 2014, 7:34am UTC](https://discuss.elastic.co/t/i-have-a-doubt-at-how-to-avoiding-type-gotchas/18893 "2014-07-25T07:34:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![xu\_piao](https://avatars.discourse-cdn.com/v4/letter/x/f14d63/32.png) [@xu\_piao](https://discuss.elastic.co/u/xu_piao)\
**Post date:** [July 25, 2014, 7:34am UTC](https://discuss.elastic.co/t/i-have-a-doubt-at-how-to-avoiding-type-gotchas/18893/1 "2014-07-25T07:34:59Z")

</div>

[http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/mapping.html#\_avoiding\_type\_gotchas](http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/mapping.html#_avoiding_type_gotchas)

at above guidence it say i can use \_type + field name to avoid analyzer  
conflicts. but i have try many times all is no use.

i have a index with two type is group and user which all have 'region'  
field conflict .

group :

- region: {
  - type: string
  - store: true
  - analyzer: ik  
}

user:

- region: {
  - type: "long"  
}

as guidence say :

We can avoid this problem either by naming the fields differently — eg  
title\_en and title\_es — or by explicitly including the type name in the  
field name and querying each field separately:

GET /\_search  
{  
"query": {  
"multi\_match": { [http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/mapping.html#CO30-1](http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/mapping.html#CO30-1)  
"query": "The quick brown fox",  
"fields": ["blog\_en.title", "blog\_es.title"]  
}  
}  
}

I do query like this  
{  
"bool" : {  
"must" : {  
"query\_string" : {  
"query" : ""北京西路"",  
"fields" : [ "group.name^20", "group.tags^5", "group.intra^1",  
"group.region^2", "group.address^2" ]  
}  
},  
"minimum\_should\_match" : "1"  
}  
}

but no use . it still throw exception .

why ???

exception :  
org.elasticsearch.search.query.QueryPhaseExecutionException: [matrix][4]:  
query[filtered((name:"闵行区 吴 宝 路"^20.0 | tags:"闵行区 吴 宝 路"^5.0 | intra:"闵行区 吴  
宝 路" | region:"闵行区 吴 宝 路"^2.0 | address:"闵行区 吴 宝  
路"^2.0))-\>cache(\_type:group)],from[0],size[20]: Query Failed [Failed to  
execute main query]  
at  
org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:127)  
at  
org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:257)  
at  
org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteQuery(SearchServiceTransportAction.java:202)  
at  
org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryThenFetchAction.java:80)  
at  
org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:216)  
at  
org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$4.run(TransportSearchTypeAction.java:292)  
at  
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)  
at  
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)  
at java.lang.Thread.run(Thread.java:722)  
Caused by: java.lang.IllegalStateException: field "region" was indexed  
without position data; cannot run PhraseQuery (term=闵行区)  
at  
org.apache.lucene.search.PhraseQuery$PhraseWeight.scorer(PhraseQuery.java:278)  
at  
org.apache.lucene.search.DisjunctionMaxQuery$DisjunctionMaxWeight.scorer(DisjunctionMaxQuery.java:161)  
at  
org.apache.lucene.search.FilteredQuery$RandomAccessFilterStrategy.filteredScorer(FilteredQuery.java:531)  
at  
org.apache.lucene.search.FilteredQuery$1.scorer(FilteredQuery.java:136)  
at  
org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:618)  
at  
org.elasticsearch.search.internal.ContextIndexSearcher.search(ContextIndexSearcher.java:173)  
at  
org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:491)  
at  
org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:448)  
at  
org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:281)  
at  
org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:269)  
at  
org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:123)  
... 8 more

--  
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/5d8e0efc-da58-4a5f-a694-3357cf5d10d8%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5d8e0efc-da58-4a5f-a694-3357cf5d10d8%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [July 25, 2014, 5:16pm UTC](https://discuss.elastic.co/t/i-have-a-doubt-at-how-to-avoiding-type-gotchas/18893/2 "2014-07-25T17:16:19Z")

</div>

Hi,

The issue is that the `region` field in `group` is indexed with positional  
data, while the `region` field in `user` is indexed without. This is  
something that Elasticsearch cannot deal with. You should try to give the  
`region` field different names in `group` and `user`.

On Fri, Jul 25, 2014 at 9:34 AM, xu piao [xupiaobj@gmail.com](mailto:xupiaobj@gmail.com) wrote:

> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/mapping.html#_avoiding_type_gotchas)
> 
> at above guidence it say i can use \_type + field name to avoid analyzer  
> conflicts. but i have try many times all is no use.
> 
> i have a index with two type is group and user which all have 'region'  
> field conflict .
> 
> group :
> 
> - region: {
> - type: string
> - store: true
> - analyzer: ik  
> }
> 
> user:
> 
> - region: {
> - type: "long"  
> }
> 
> as guidence say :
> 
> We can avoid this problem either by naming the fields differently — eg  
> title\_en and title\_es — or by explicitly including the type name in the  
> field name and querying each field separately:
> 
> GET /\_search  
> {  
> "query": {  
> "multi\_match": { [http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/mapping.html#CO30-1](http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/mapping.html#CO30-1)  
> "query": "The quick brown fox",  
> "fields": ["blog\_en.title", "blog\_es.title"]  
> }  
> }  
> }
> 
> I do query like this  
> {  
> "bool" : {  
> "must" : {  
> "query\_string" : {  
> "query" : ""北京西路"",  
> "fields" : [ "group.name^20", "group.tags^5", "group.intra^1",  
> "group.region^2", "group.address^2" ]  
> }  
> },  
> "minimum\_should\_match" : "1"  
> }  
> }
> 
> but no use . it still throw exception .
> 
> why ???
> 
> exception :  
> org.elasticsearch.search.query.QueryPhaseExecutionException: [matrix][4]:  
> query[filtered((name:"闵行区 吴 宝 路"^20.0 | tags:"闵行区 吴 宝 路"^5.0 | intra:"闵行区 吴  
> 宝 路" | region:"闵行区 吴 宝 路"^2.0 | address:"闵行区 吴 宝  
> 路"^2.0))-\>cache(\_type:group)],from[0],size[20]: Query Failed [Failed to  
> execute main query]  
> at  
> org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:127)  
> at  
> org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:257)  
> at  
> org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteQuery(SearchServiceTransportAction.java:202)  
> at  
> org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryThenFetchAction.java:80)  
> at  
> org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:216)  
> at  
> org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$4.run(TransportSearchTypeAction.java:292)  
> at  
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)  
> at  
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)  
> at java.lang.Thread.run(Thread.java:722)  
> Caused by: java.lang.IllegalStateException: field "region" was indexed  
> without position data; cannot run PhraseQuery (term=闵行区)  
> at  
> org.apache.lucene.search.PhraseQuery$PhraseWeight.scorer(PhraseQuery.java:278)  
> at  
> org.apache.lucene.search.DisjunctionMaxQuery$DisjunctionMaxWeight.scorer(DisjunctionMaxQuery.java:161)  
> at  
> org.apache.lucene.search.FilteredQuery$RandomAccessFilterStrategy.filteredScorer(FilteredQuery.java:531)  
> at  
> org.apache.lucene.search.FilteredQuery$1.scorer(FilteredQuery.java:136)  
> at  
> org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:618)  
> at  
> org.elasticsearch.search.internal.ContextIndexSearcher.search(ContextIndexSearcher.java:173)  
> at  
> org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:491)  
> at  
> org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:448)  
> at  
> org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:281)  
> at  
> org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:269)  
> at  
> org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:123)  
> ... 8 more
> 
> --  
> 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/5d8e0efc-da58-4a5f-a694-3357cf5d10d8%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5d8e0efc-da58-4a5f-a694-3357cf5d10d8%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/5d8e0efc-da58-4a5f-a694-3357cf5d10d8%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/5d8e0efc-da58-4a5f-a694-3357cf5d10d8%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
Adrien Grand

--  
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/CAL6Z4j7xpxcKpFv%2BzZpwY7EDyHwq-6aitAvght9BP2rCk4-86Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j7xpxcKpFv%2BzZpwY7EDyHwq-6aitAvght9BP2rCk4-86Q%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![xu\_piao](https://avatars.discourse-cdn.com/v4/letter/x/f14d63/32.png) [@xu\_piao](https://discuss.elastic.co/u/xu_piao)\
**Post date:** [July 28, 2014, 5:30am UTC](https://discuss.elastic.co/t/i-have-a-doubt-at-how-to-avoiding-type-gotchas/18893/3 "2014-07-28T05:30:22Z")

</div>

Hi

Why it no use when i explicitly type name to separate query field ?

or that meanning : only two type 'region' field all indexed can use this  
way to separate query field , not one of them is indexed can use?

sorry my english is poor .

Maybe I did not express clearly what I mean。

在 2014年7月26日星期六UTC+8上午1时16分25秒，Adrien Grand写道：

> Hi,
> 
> The issue is that the `region` field in `group` is indexed with positional  
> data, while the `region` field in `user` is indexed without. This is  
> something that Elasticsearch cannot deal with. You should try to give the  
> `region` field different names in `group` and `user`.
> 
> On Fri, Jul 25, 2014 at 9:34 AM, xu piao \<[xupi...@gmail.com](mailto:xupi...@gmail.com) \<javascript:\>\>  
> wrote:
> 
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/mapping.html#_avoiding_type_gotchas)
> > 
> > at above guidence it say i can use \_type + field name to avoid analyzer  
> > conflicts. but i have try many times all is no use.
> > 
> > i have a index with two type is group and user which all have 'region'  
> > field conflict .
> > 
> > group :
> > 
> > - region: {
> > - type: string
> > - store: true
> > - analyzer: ik  
> > }
> > 
> > user:
> > 
> > - region: {
> > - type: "long"  
> > }
> > 
> > as guidence say :
> > 
> > We can avoid this problem either by naming the fields differently — eg  
> > title\_en and title\_es — or by explicitly including the type name in the  
> > field name and querying each field separately:
> > 
> > GET /\_search  
> > {
> > 
> > ```
> > "query": {
> > 
> > "multi_match": { <http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/mapping.html#CO30-1>
> > 
> > "query": "The quick brown fox",
> > 
> > "fields": ["blog_en.title", "blog_es.title"]
> > 
> > }
> > }
> > 
> > ```
> > 
> > }
> > 
> > I do query like this  
> > {  
> > "bool" : {  
> > "must" : {  
> > "query\_string" : {  
> > "query" : ""北京西路"",  
> > "fields" : [ "group.name^20", "group.tags^5", "group.intra^1",  
> > "group.region^2", "group.address^2" ]  
> > }  
> > },  
> > "minimum\_should\_match" : "1"  
> > }  
> > }
> > 
> > but no use . it still throw exception .
> > 
> > why ???
> > 
> > exception :  
> > org.elasticsearch.search.query.QueryPhaseExecutionException: [matrix][4]:  
> > query[filtered((name:"闵行区 吴 宝 路"^20.0 | tags:"闵行区 吴 宝 路"^5.0 | intra:"闵行区 吴  
> > 宝 路" | region:"闵行区 吴 宝 路"^2.0 | address:"闵行区 吴 宝  
> > 路"^2.0))-\>cache(\_type:group)],from[0],size[20]: Query Failed [Failed to  
> > execute main query]  
> > at  
> > org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:127)  
> > at  
> > org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:257)  
> > at  
> > org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteQuery(SearchServiceTransportAction.java:202)  
> > at  
> > org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryThenFetchAction.java:80)  
> > at  
> > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:216)  
> > at  
> > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$4.run(TransportSearchTypeAction.java:292)  
> > at  
> > java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)  
> > at  
> > java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)  
> > at java.lang.Thread.run(Thread.java:722)  
> > Caused by: java.lang.IllegalStateException: field "region" was indexed  
> > without position data; cannot run PhraseQuery (term=闵行区)  
> > at  
> > org.apache.lucene.search.PhraseQuery$PhraseWeight.scorer(PhraseQuery.java:278)  
> > at  
> > org.apache.lucene.search.DisjunctionMaxQuery$DisjunctionMaxWeight.scorer(DisjunctionMaxQuery.java:161)  
> > at  
> > org.apache.lucene.search.FilteredQuery$RandomAccessFilterStrategy.filteredScorer(FilteredQuery.java:531)  
> > at  
> > org.apache.lucene.search.FilteredQuery$1.scorer(FilteredQuery.java:136)  
> > at  
> > org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:618)  
> > at  
> > org.elasticsearch.search.internal.ContextIndexSearcher.search(ContextIndexSearcher.java:173)  
> > at  
> > org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:491)  
> > at  
> > org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:448)  
> > at  
> > org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:281)  
> > at  
> > org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:269)  
> > at  
> > org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:123)  
> > ... 8 more
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/5d8e0efc-da58-4a5f-a694-3357cf5d10d8%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5d8e0efc-da58-4a5f-a694-3357cf5d10d8%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/5d8e0efc-da58-4a5f-a694-3357cf5d10d8%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/5d8e0efc-da58-4a5f-a694-3357cf5d10d8%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> Adrien Grand

--  
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/c51a8004-4e20-45e4-a487-c1a9886a254d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c51a8004-4e20-45e4-a487-c1a9886a254d%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:12am UTC](https://discuss.elastic.co/t/i-have-a-doubt-at-how-to-avoiding-type-gotchas/18893/4 "2017-07-06T01:12:53Z")

</div>


