Exemple #1
0
def test_elasticsearch_custom_fields(elasticsearch_fixture):
    client = Elasticsearch()
    client.indices.delete(index='haystack_test_custom', ignore=[404])
    document_store = ElasticsearchDocumentStore(index="haystack_test_custom", text_field="custom_text_field",
                                                embedding_field="custom_embedding_field")

    doc_to_write = {"custom_text_field": "test", "custom_embedding_field": np.random.rand(768).astype(np.float32)}
    document_store.write_documents([doc_to_write])
    documents = document_store.get_all_documents(return_embedding=True)
    assert len(documents) == 1
    assert documents[0].text == "test"
    np.testing.assert_array_equal(doc_to_write["custom_embedding_field"], documents[0].embedding)
    split_respect_sentence_boundary=False,
    split_overlap=0)

as4Docs = processor.process(as4)
# print(as4Docs)

for i in range(0, len(as4Docs)):
    print(i)
    print(":\n")
    print(as4Docs[i])
    print("---------------")

# ! docker run -d -p 9200:9200 -e "discovery.type=single-node" elasticsearch:7.6.2

from haystack.document_store.elasticsearch import ElasticsearchDocumentStore
document_store = ElasticsearchDocumentStore(host="localhost",
                                            username="",
                                            password="",
                                            index="document")

document_store.delete_all_documents()
document_store.write_documents(as4Docs)

backagain = document_store.get_all_documents()

for i in range(0, len(backagain)):
    print(i)
    print(":\n")
    print(backagain[i])
    print("---------------")