# Managing namespace conflicts with Jbuilder/rspec when creating boolean queries/filters with "should"

**URL:** <https://discuss.elastic.co/t/managing-namespace-conflicts-with-jbuilder-rspec-when-creating-boolean-queries-filters-with-should/14800>\
**Category:** Elasticsearch\
**Created:** [December 10, 2013, 9:12pm UTC](https://discuss.elastic.co/t/managing-namespace-conflicts-with-jbuilder-rspec-when-creating-boolean-queries-filters-with-should/14800 "2013-12-10T21:12:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![loren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/loren/32/44942_2.png) [@loren](https://discuss.elastic.co/u/loren)\
**Post date:** [December 10, 2013, 9:12pm UTC](https://discuss.elastic.co/t/managing-namespace-conflicts-with-jbuilder-rspec-when-creating-boolean-queries-filters-with-should/14800/1 "2013-12-10T21:12:36Z")

</div>

I'm posting this in case someone else runs across this problem.

If you are using Jbuilder [https://github.com/rails/jbuilder](https://github.com/rails/jbuilder) to compose  
your JSON for an Elasticsearch boolean query[http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html) you  
might end up using the "should" typed occurrence.

$ irb  
2.0.0p195 :001 \> require 'jbuilder'  
=\> true  
2.0.0p195 :002 \> Jbuilder.encode do |json|  
2.0.0p195 :003 \> json.should do  
2.0.0p195 :004 \> json.foo "this works"  
2.0.0p195 :005?\> end  
2.0.0p195 :006?\> end  
=\> "{"should":{"foo":"this works"}}"

But if you also use RSpec [http://rspec.info](http://rspec.info) in your project, you will run  
into this namespace conflict:

2.0.0p195 :007 \> require 'rspec'  
=\> true  
2.0.0p195 :008 \> Jbuilder.encode do |json|  
2.0.0p195 :009 \> json.should do  
2.0.0p195 :010 \> json.foo "this does not work"  
2.0.0p195 :011?\> end  
2.0.0p195 :012?\> end  
=\> "{}”

Here is the workaround:  
2.0.0p195 :013 \> Jbuilder.encode do |json|  
2.0.0p195 :014 \> json.set! :should do  
2.0.0p195 :015 \> json.foo "this works again"  
2.0.0p195 :016?\> end  
2.0.0p195 :017?\> end  
=\> "{"should":{"foo":"this works again"}}"

--  
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/9749e705-9447-4af6-839c-546c69021a0a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9749e705-9447-4af6-839c-546c69021a0a%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:02am UTC](https://discuss.elastic.co/t/managing-namespace-conflicts-with-jbuilder-rspec-when-creating-boolean-queries-filters-with-should/14800/2 "2017-07-06T02:02:07Z")

</div>

Closed on July 6, 2017, 2:02am UTC


