Using Intersect

To return only documents that match all provided sub-queries, use the intersect() method which enables RavenDB to perform server-side intersection queries.

Syntax

query.intersect();

Example

// return all T-shirts that are manufactured by 'Raven'
// and contain both 'Small Blue' and 'Large Gray' types
const tShirts = await session
    .query({ indexName: "TShirts/ByManufacturerColorSizeAndReleaseYear" })
    .whereEquals("manufacturer", "Raven")
    .intersect()
    .whereEquals("color", "Blue")
    .andAlso()
    .whereEquals("size", "Small")
    .intersect()
    .whereEquals("color", "Gray")
    .andAlso()
    .whereEquals("size", "Large")
    .toList();
class TShirts_ByManufacturerColorSizeAndReleaseYearResult {
    constructor(data) {
        this.manufacturer = data.manufacturer;
        this.color = data.color;
        this.size = data.size;
        this.releaseYear = data.releaseYear;
    }
}

class TShirts_ByManufacturerColorSizeAndReleaseYear extends AbstractIndexCreationTask {

    constructor() {
        super();

        this.map = `docs.TShirts.SelectMany(tshirt => tshirt.types, (tshirt, type) => new {
                manufacturer = tshirt.manufacturer,
                color = type.color,
                size = type.size,
                releaseYear = tshirt.releaseYear
            })`;
    }
}
from index 'TShirts/ByManufacturerColorSizeAndReleaseYear' 
where intersect(manufacturer = 'Raven', color = 'Blue' and size = 'Small', color = 'Gray' and size = 'Large')