In signals.py I want to add body ={
"suggest" : {
"input": [ instance.name,instance.username ],
"weight" : 34
}
}
instance.indexing() # index for the searching
instance.auto_indexing() # index for autocomplete
searchable_user = UserSearch.objects.get(user=instance)
id = searchable_user.user_id
searchable_user = UserSearch.objects.get(user=instance)
id = searchable_user.user_id
if es.exists("autoidx","user_search",id):
body = {"suggest": {"input": [instance.name, instance.username, instance.company,instance.company_address]}}
es.update("autoidx", "user_search", id, body=body)
print("Bye")
The last print is not coming and throwing the above error.I want to add the suggester part into each and every doc in autoidx index so that it can come in autocompletion
Thanks
@riemannzeta1191 FYI you can use the ` character 3 time in a row to create a code block. It makes things a little easier to read. Just a comment for future use :)
for example
body = {
"suggest" : {
"input": [ instance.name,instance.username ],
"weight" : 34
}
}
instance.indexing() # index for the searching
instance.auto_indexing() # index for autocomplete
searchable_user = UserSearch.objects.get(user=instance)
id = searchable_user.user_id
searchable_user = UserSearch.objects.get(user=instance)
id = searchable_user.user_id
if es.exists("autoidx","user_search",id):
body = {"suggest": {"input": [instance.name, instance.username, instance.company,instance.company_address]}}
es.update("autoidx", "user_search", id, body=body)
print("Bye")
As for the nature of the error you're receiving.
A 400 error indicates that the body your sending to ES is malformed. It is expecting the body to be in the form of
{
"doc":{},
"script":{}
}
You can see what the ES API is expecting when doing an update by looking at the docs here: https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html#_updates_with_a_partial_document
I think what you need to do is in your if statement, you should format the body so that it conforms to the body that the ES API is expecting.
Please let us know if you have any other issues.
Most helpful comment
As for the nature of the error you're receiving.
A 400 error indicates that the
bodyyour sending to ES is malformed. It is expecting the body to be in the form ofYou can see what the ES API is expecting when doing an update by looking at the docs here: https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html#_updates_with_a_partial_document
I think what you need to do is in your
ifstatement, you should format thebodyso that it conforms to thebodythat the ES API is expecting.Please let us know if you have any other issues.