2

I'm using python's elasticsearch module to connect and search through my elasticsearch cluster.

In the cluster, one of the fields in my index is 'message' - I want to query my elastic, from python, for a specific value in this 'message' field.

Here is my basic search which simply returns all logs of a specific index.

    es = elasticsearch.Elasticsearch(source_cluster)
    doc = {
        'size' : 10000,
        'query': {
            'match_all' : {}
        }
    }
res = es.search(index='test-index', body=doc, scroll='1m')

How should I change this query in order to find all results with the word 'moved' in their 'message' field?

The equivalent query that does it from Kibana is:

_index:test-index && message: moved

Thanks,

Noam

1 Answer 1

9

You need to use the match query. Try this:

doc = {
    'size' : 10000,
    'query': {
        'match' : {
            'message': 'moved'
        }
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

You may close :)

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.