Elasticsearch "starts with" first word in phrases

If you are using default mapping then it will not work for you.

You need to use keyword tokenizer and lowercase filter in mapping.

Mapping Will be :

{
    "settings": {
        "index": {
            "analysis": {
                "analyzer": {
                    "analyzer_startswith": {
                        "tokenizer": "keyword",
                        "filter": "lowercase"
                    }
                }
            }
        }
    },
    "mappings": {
        "test_index": {
            "properties": {
                "title": {
                    "search_analyzer": "analyzer_startswith",
                    "index_analyzer": "analyzer_startswith",
                    "type": "string"
                }
            }
        }
    }
}

Search query on test_index :

{
    "query": {
        "match_phrase_prefix": {
            "title": {
                "query": "a"
            }
        }
    }
}

It will return all post title starting with a


Alternatively, can use span_near:

GET your_index/_search
{
  "query": {
    "span_first": {
      "match": {
        "span_term": {
          "your_field": "first_token"
        }
      },
      "end": 1
    }
  },
  "_source": "your_field"
}