loopbackio / loopback-connector-elastic-search

Strongloop Loopback connector for Elasticsearch
MIT License
78 stars 57 forks source link

add uniqueness validation for a field, ES-2.4 #114

Closed sukheja-varun closed 5 years ago

sukheja-varun commented 6 years ago

I want to add uniqueness validation to field name for my model. I am using it as Units.validatesUniquenessOf('name.raw', {message: 'Name already exists'}); but it is not working with name.raw. It works if I only mention name as shown below Units.validatesUniquenessOf('name', {message: 'Name already exists'}); but in this case, it sends error even if I enter different names but having the same keyword such as, name1: myName1 name2: myName2

pulkitsinghal commented 6 years ago

Warning: this rabbit hole might go quite deep.

Waning: following may be a wild goose chase so until you come to terms with the big picture yourself, you might not enjoy accepting suggestions from others:

  1. I would find out what tokens are created for name when values myName1 and myName2 are provided. Maybe there are multiple tokenized values like myname, 1 and myname,2
  2. Then I would check how the built-in validatesUniquenessOf compares the values. Does it compare myName1 with myName2 or does it soft compare one of the tokens myname with myname returned by ES and use that limited knowledge to declare that the values are not unique?
aquid commented 5 years ago

@pulkitsinghal second point is the actual answer.

Does it compare myName1 with myName2 or does it soft compare one of the tokens myname with myname returned by ES

@sukheja-varun I hope you have your answers so I will be closing this issue now. Please request for re-open in case you want to discuss anything more.