# Customer Overrides of a document

**URL:** https://discuss.elastic.co/t/customer-overrides-of-a-document/897
**Category:** Elasticsearch
**Created:** [May 19, 2015, 12:38pm UTC](https://discuss.elastic.co/t/customer-overrides-of-a-document/897 "2015-05-19T12:38:59Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![sumi](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@sumi](https://discuss.elastic.co/u/sumi)
#### Post date: [May 19, 2015, 12:38pm UTC](https://discuss.elastic.co/t/customer-overrides-of-a-document/897/1 "2015-05-19T12:38:59Z")

</div>

Hey all,

got a little question where I'm currently stuck at.

Here's the use case:  
Having a index that provides documents such as IT Services which are provided to the customer. The user want's to search through all available services. That's fairly easy to achieve. Now comes the problem where i am stuck.  
Customer A has a special price for the IT-Service DatabaseMigration in example. All other user's will pay the default price.

How can i achieve something like that. Having a document like that. Customer A should pay only 1000.00  
{  
topic: "DatabaseMigration",  
price: 1500.00  
category: ["Database.Migration"]  
includedWorkHours: 20  
}

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [May 20, 2015, 8:32am UTC](https://discuss.elastic.co/t/customer-overrides-of-a-document/897/2 "2015-05-20T08:32:41Z")

</div>

You could have a new field with the price for that customer, you'd have to deal with querying and then merging multiple fields though.

---

<div class="post-metadata">

### Author: ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)
#### Post date: [May 20, 2015, 12:47pm UTC](https://discuss.elastic.co/t/customer-overrides-of-a-document/897/3 "2015-05-20T12:47:26Z")

</div>

I've seen people use scripting for this when most prices need some kind of  
transformation. You end up using scripted fields and scripted sorts. Its  
not 100% the fastest thing but it works pretty well I think.

If you just have _some_ overrides you could index two documents: one for  
the default prices and one for the override price. Like so:

```auto
{
  "product": "123",
  "price": 1,
  "not_for": ["customer_c"]
}

```

and

```auto
{
  "product": "123",
  "price": .5,
  "just_for": ["customer_c"]
}

```

Then you filter out the results: add a bool filter with  
minimum\_should\_match=1 and three clauses:

1. The "just\_for" field should be missing
2. The "just\_for" field should contain "customer\_c"
3. The "not\_for" field must not contain "customer\_c"

You'd need to make not\_for and just\_for not\_analyzed but otherwise this  
should work and be faster than running a script on every result. Depending  
on the number of products it doesn't really matter though.

This not\_for, just\_for thing is similar to how we combine search results  
from commons and the local wiki when you, say, search for "cats  
[https://en.wikipedia.org/wiki/Special:Search/file:cats](https://en.wikipedia.org/wiki/Special:Search/file:cats)" in enwiki. You  
get results from [commons.wikimedia.org](http://commons.wikimedia.org) and from [en.wikipedia.org](http://en.wikipedia.org)  
deduplicated.

---

<div class="post-metadata">

### Author: ![sumi](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@sumi](https://discuss.elastic.co/u/sumi)
#### Post date: [May 20, 2015, 3:44pm UTC](https://discuss.elastic.co/t/customer-overrides-of-a-document/897/4 "2015-05-20T15:44:49Z")

</div>

Okay thanks for the info.  
But just wildly guessing if you have a big index with let's say a thousands of products and let's say 20% of the customer's would have their own price. How can you still organize that ?

```
{
  "product": "123",
  "price": 1,
  "not_for": ["customer_c", "customer_d","customer_e","customer_f","customer_g"]
}
```

---

<div class="post-metadata">

### Author: ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)
#### Post date: [May 20, 2015, 4:12pm UTC](https://discuss.elastic.co/t/customer-overrides-of-a-document/897/5 "2015-05-20T16:12:35Z")

</div>

You could do that, but if 20% of the customers have an override on 100% of  
the stuff its probably going to be a costly way to do it. It might make  
more sense just to use a script at search time -or- if customers fall into  
dozen or so classes then it'd make sense to have different fields for the  
price per class. Or something like that.

---

<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, 12:13am UTC](https://discuss.elastic.co/t/customer-overrides-of-a-document/897/6 "2017-07-06T00:13:00Z")

</div>


