2

I'm trying to code a simple python script which should ask for a string to be inserted by shell and use it as "match string" in a match query. I post here the script so the problem can be better understandable.

client = Elasticsearch()

query_string = raw_input("Enter your query string: ")
print(query_string)

s = Search(using=client, index="enron_test"
    .query("match", message_body=query_string))

response = s.execute()

Actually, I should get all the json documents (each represents an email) which contain the string "query_string" in the message_body field.

The problem is that when I run the script, I get this error: AttributeError: 'str' object has no attribute 'query'. I'm a newbie in Elasticsearch, where am I wrong? Or maybe this thing I'm trying to do is not possible?

1 Answer 1

1

Right now you are calling the query method on the string "enrox_test".

I dont know what library you are using so I cant check the syntax. But I think you are missing something between "enron_text" and ".query(..."

Sign up to request clarification or add additional context in comments.

3 Comments

I'm using this libraries from elasticsearch import Elasticsearch and from elasticsearch_dsl import Search
You are missing a closing parenthesis after "enron-text". You can check out one of the search example here for the syntax of the search request here : elasticsearch-dsl.readthedocs.io/en/latest
If this solves the problem, please do close the question and mark as the answer. It can help someone else with a similar error :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.