you just need to add quotes in the copy_to definition:
class NameDoc(Document):
"""
Elastic document definition for name.
"""
full_name = Text()
first_name = Text(copy_to="full_name")
last_name = Text(copy_to="full_name")
Hope this helps!
Didn't work. This is what the mapping looks like:
"mappings": {
"doc": {
"properties": {
"last_name": {
"type": "text",
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
}
},
"first_name": {
"type": "text",
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
}
}
}
}
}
This is my code:
import elasticsearch
from elasticsearch_dsl import Document, Text, Index
index_name = "test4"
es6_client = elasticsearch.Elasticsearch("localhost:9200")
class NameDoc(Document):
full_name = Text()
first_name = Text(copy_to="full_name")
last_name = Text(copy_to="full_name")
def start():
test_index = Index(index_name)
test_index.create(using=es6_client)
def index():
names = [("John", "Legend"), ("Henry", "Miller"), ("John", "Miller"), ("Henry", "Legend")]
for firstName, lastName in names:
doc = NameDoc()
doc.meta.id = "{}{}".format(firstName[0], lastName[0])
doc.first_name = firstName
doc.last_name = lastName
doc.save(using=es6_client, index=index_name)
if __name__ == "__main__":
start()
index()
How did you create the mappings? When I use your NameDoc definiton to create the index I can see the copy_to fields being properly set.
Thanks!
Ah! missing the init. Thanks for pointing to the right direction
Most helpful comment
you just need to add quotes in the
copy_todefinition:Hope this helps!