Customer Overrides of a document


#1

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
}


(Mark Walkom) #2

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.


(Nik Everett) #3

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:

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

and

{
  "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" in enwiki. You
get results from commons.wikimedia.org and from en.wikipedia.org
deduplicated.


#4

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"]
}

(Nik Everett) #5

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.


(system) #6