2

I'm trying to use ElasticSearch to find all records containing a particular string. I'm using a match query for this, and it's working fine.

Now, I'm trying to sort the results based on a particular field. When I try this, I get some very unexpected output, and none of the records even contain my initial search query.

My request is structured as follows:

{
"query": 
{
    "match": {"_all": "some_search_string"}
 },
 "sort": [
 {
    "some_field": {
        "order": "asc"
        }
 }
 ] }

Am I doing something wrong here?

1
  • did you get solution? Commented May 19, 2020 at 14:34

1 Answer 1

1

In order to sort on a string field, your mapping must contain a non-analyzed version of this field. Here's a simple blog post I found that describes how you can do this using the multi_field mapping type.

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

2 Comments

Thanks, but I don't think that's the issue. If I search for a particular term instead of using the match query, the sorting works just fine. For eg, if I try: "query": { "term": {"some_field": "some_Search_String"} }, the sorting works out. Is there some issue while using the sort feature with match in particular? I appreciate the help!
The provided link is not working anymore.

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.