Search code examples
azureluceneazure-cognitive-search

Azure Search match against two properties of the same object


I would like to do a query matches against two properties of the same item in a sub-collection.

Example:

[
  {
    "name": "Person 1",
    "contacts": [
        { "type": "email", "value": "[email protected]" },
        { "type": "phone", "value": "555-12345" },
    ]
  }
]

I would like to be able to search by emails than contain xpto.org but,
doing something like the following doesn't work:

search.ismatchscoring('email','contacts/type,','full','all') and search.ismatchscoring('/.*xpto.org/','contacts/value,','full','all')

instead, it will consider the condition in the context of the main object and objects like the following will also match:

[
  {
    "name": "Person 1",
    "contacts": [
        { "type": "email", "value": "555-12345" },
        { "type": "phone", "value": "[email protected]" },
    ]
  }
]

Is there any way around this without having an additional field that concatenates type and value?


Solution

  • The solution I've implemented was creating different collections per contact type.

    This way I'm able to search directly in, lets say, the email collection without the need for correlated search. It might not be the solution for all cases but it works well in this case.