Mutiple field full-text search using elasticsearch
[Elasticsearch]() is a [Java]() application and set of shell scripts
that makes it nearly trivial to add full-text search to your web
application. It’s powered by [Apache Lucene](), but its got a
significantly lower barrier-to-entry as you can see from the [intro
slides](http://www.elasticsearch.com/products/elasticsearch/). I could extoll numerous virtues of Elasticsearch, but there’s one I
think is particularly cool: you get a full query syntax language out
of the box. So, for example, you can allow your users to do searches
of your documents like “+monkey +ape -gorilla” or “cheese AND crackers
OR pickles” without having to parse the query yourself. However, I
could not figure out how to do multiple field full-text search using
elasticsearch until some helpful soul in the #elasticsearch IRC
channel told me: you need to wrap it in a [boolean
query](http://www.elasticsearch.com/docs/elasticsearch/rest_api/query_dsl/bool_query/).
So, if I have documents with “abstract” and “title” fields and a
corresponding web form into which a user submits ‘Kyle AND “body
odor”’ and ‘heat OR wave’ (respectively) I’d translate that into the
elasticsearch JSON search syntax as follows:
That’s it. Super cool. Super easy. Using elasticsearch’s boolean
query you could designed monstrous “advanced search” forms in a flash.
that makes it nearly trivial to add full-text search to your web
application. It’s powered by [Apache Lucene](), but its got a
significantly lower barrier-to-entry as you can see from the [intro
slides](http://www.elasticsearch.com/products/elasticsearch/). I could extoll numerous virtues of Elasticsearch, but there’s one I
think is particularly cool: you get a full query syntax language out
of the box. So, for example, you can allow your users to do searches
of your documents like “+monkey +ape -gorilla” or “cheese AND crackers
OR pickles” without having to parse the query yourself. However, I
could not figure out how to do multiple field full-text search using
elasticsearch until some helpful soul in the #elasticsearch IRC
channel told me: you need to wrap it in a [boolean
query](http://www.elasticsearch.com/docs/elasticsearch/rest_api/query_dsl/bool_query/).
So, if I have documents with “abstract” and “title” fields and a
corresponding web form into which a user submits ‘Kyle AND “body
odor”’ and ‘heat OR wave’ (respectively) I’d translate that into the
elasticsearch JSON search syntax as follows:
1 2 | {‘bool’: {‘must’: [{‘field’: {‘abstract’: {‘query’: ‘Kyle AND “body odor”’}}}, {‘field’: {‘title’: {‘query’: ‘heat OR wave’}}}]}} |
query you could designed monstrous “advanced search” forms in a flash.




1 year ago