I have the following database in Clusterpoint:
<db>
<document>
<id>1</id>
<name lang="en">John</name>
<name lang="ru">Джон</name>
</document>
<document>
<id>2</id>
<name lang="en">Bill</name>
<name lang="ru">Билл</name>
</document>
</db>
I am willing to perform a query searching for a specific name. Normally I would specify:
<query><name>Bill</name></query>
However this might match both English and Russian name.
How can I make sure that search would only look inside name with attribute lang="en"
?
It is possible to define attributes as child tags in request and use them in search, aggregation, ordering etc.
If you want to search for the <name> with certain attribute value, then just specify it in query:
This will search for documents where both conditions are matched. So, if your database contains, for example, documents (I've added document with id=3):
then query mentioned above (with defined attributes) will return document with id=2.
But if you will search by:
then you will get two documents with id=2 and id=3.
Be carefull, if there are repetitive tags, than it is necessary to use tag colocation by defining rule "colocate=yes" in policy configuration for appropriate tag (in your case - <name>), and by using "@" operator in query.
If you add document to your database:
And will try to return documents, where both conditions match values inside one repetitive tag, then query:
will return incorrect result - documents with id=1 and id=4.
But by defining "colocate=yes" for <name> and using "@" operator:
you will get correct one - with id=1.