def test_search_with_filter(self, sync_client: Elasticsearch, index: str) -> None:
        """Test end to end construction and search with metadata."""
        store = VectorStore(
            index=index,
            retrieval_strategy=DenseVectorStrategy(),
            embedding_service=FakeEmbeddings(),
            client=sync_client,
        )

        texts = ["foo", "foo", "foo"]
        metadatas = [{"page": i} for i in range(len(texts))]
        store.add_texts(texts=texts, metadatas=metadatas)

        def assert_query(query_body: dict, query: Optional[str]) -> dict:
            assert query_body == {
                "knn": {
                    "field": "vector_field",
                    "filter": [{"term": {"metadata.page": "1"}}],
                    "k": 3,
                    "num_candidates": 50,
                    "query_vector": [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0],
                }
            }
            return query_body

        output = store.search(
            query="foo",
            k=3,
            filter=[{"term": {"metadata.page": "1"}}],
            custom_query=assert_query,
        )
        assert [doc["_source"]["text_field"] for doc in output] == ["foo"]
        assert [doc["_source"]["metadata"]["page"] for doc in output] == [1]
Test end to end construction and search with metadata.
test_elasticsearch/test_server/test_vectorstore/test_vectorstore.py