# Elasticsearch as a datastore for rules

**URL:** <https://discuss.elastic.co/t/elasticsearch-as-a-datastore-for-rules/8369>\
**Category:** Elasticsearch\
**Created:** [July 10, 2012, 4:37am UTC](https://discuss.elastic.co/t/elasticsearch-as-a-datastore-for-rules/8369 "2012-07-10T04:37:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sandeep\_Srinivasa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sandeep_srinivasa/32/50506_2.png) [@Sandeep\_Srinivasa](https://discuss.elastic.co/u/Sandeep_Srinivasa)\
**Post date:** [July 10, 2012, 4:37am UTC](https://discuss.elastic.co/t/elasticsearch-as-a-datastore-for-rules/8369/1 "2012-07-10T04:37:40Z")

</div>

hi,

I'm trying to use Elasticsearch as a datastore for rules (modeled as  
documents). The challenge is that a search returns many documents, which  
means many "rules" matched the query - I am trying to find a way to get  
Elasticsearch to rank them automagically.

For example, I have four documents

_id_:1  
_title_: sss  
_team_: a  
_not-team_:

_id_:2  
_title_: sss1  
_team_: a,b (multivalued fields)  
_not-team_:

_id_:3  
_title_ sss2  
_team_:  
_not-team_:a

_id_:4  
_title_: sss3  
_team_:  
_not-team_:

(remember that _not-team_ means that a person is NOT in team )

Now,searching for "team:a" should return three documents 1,2,4 (note that 4  
is also returned, since it does not say anything about "a" which implies a  
match) - but ranked with 1 \>\> 2 \>\> 4 starting from most specific to least  
specific.

I do expect to have a validation layer in my application as well, but it  
would be great if this can be done at the Elasticsearch level. This would  
be perfect as a NoSQL like application of Elasticsearch.

could someone point me in the right direction ?

thanks!  
-sandeep

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [July 10, 2012, 2:02pm UTC](https://discuss.elastic.co/t/elasticsearch-as-a-datastore-for-rules/8369/2 "2012-07-10T14:02:53Z")

</div>

Would something like [teams.sh · GitHub](https://gist.github.com/12a45d7e928a1693406b) work for  
you?

On Tuesday, July 10, 2012 12:37:40 AM UTC-4, Sandeep Srinivasa wrote:

> hi,
> 
> I'm trying to use Elasticsearch as a datastore for rules (modeled as  
> documents). The challenge is that a search returns many documents, which  
> means many "rules" matched the query - I am trying to find a way to get  
> Elasticsearch to rank them automagically.
> 
> For example, I have four documents
> 
> _id_:1  
> _title_: sss  
> _team_: a  
> _not-team_:
> 
> _id_:2  
> _title_: sss1  
> _team_: a,b (multivalued fields)  
> _not-team_:
> 
> _id_:3  
> _title_ sss2  
> _team_:  
> _not-team_:a
> 
> _id_:4  
> _title_: sss3  
> _team_:  
> _not-team_:
> 
> (remember that _not-team_ means that a person is NOT in team )
> 
> Now,searching for "team:a" should return three documents 1,2,4 (note that  
> 4 is also returned, since it does not say anything about "a" which implies  
> a match) - but ranked with 1 \>\> 2 \>\> 4 starting from most specific to  
> least specific.
> 
> I do expect to have a validation layer in my application as well, but it  
> would be great if this can be done at the Elasticsearch level. This would  
> be perfect as a NoSQL like application of Elasticsearch.
> 
> could someone point me in the right direction ?
> 
> thanks!  
> -sandeep

---

<div class="post-metadata">

**Author:** ![Sandeep\_Srinivasa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sandeep_srinivasa/32/50506_2.png) [@Sandeep\_Srinivasa](https://discuss.elastic.co/u/Sandeep_Srinivasa)\
**Post date:** [July 13, 2012, 6:06am UTC](https://discuss.elastic.co/t/elasticsearch-as-a-datastore-for-rules/8369/3 "2012-07-13T06:06:46Z")

</div>

On Tuesday, 10 July 2012 19:32:53 UTC+5:30, Igor Motov wrote:

> Would something like [teams.sh · GitHub](https://gist.github.com/12a45d7e928a1693406b) work  
> for you?

This was very helpful - thank you very much for taking the time. I was  
thinking of needing to build a custom plugin for scoring, but I see that I  
can probably model them as boosts. This was an example of a pretty simple  
usecase, but the rules are expected to pretty pathological. I am just  
concerned about the complexity of queries.

I will post back, once I have investigated this in some depth.

thanks!  
-sandeep

---

<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, 3:20am UTC](https://discuss.elastic.co/t/elasticsearch-as-a-datastore-for-rules/8369/4 "2017-07-06T03:20:25Z")

</div>


