Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8570805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:38:30+00:00 2026-06-11T18:38:30+00:00

I have a very basic index of users with a single type user that

  • 0

I have a very basic index of “users” with a single type “user” that has several fields to it. I don’t have anything defined on the index besides that.

What I need to do is provide autocomplete results that prioritize prefix matches (for usernames) but also contain other matches from the users bio and website and substring matches of other fields.

How does one accomplish this with the query DSL?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:38:31+00:00Added an answer on June 11, 2026 at 6:38 pm

    There are different ways to achieve what you want. I’d say it depends on the way you want to make prefix matches. You can use a Prefix Query or make EdgeNGrams out of the user field and search on it without the need of a prefix query. The first option is a little bit slower, while the second one causes an increasement of your index size since you’d index more terms (the ngrams).

    If you decide for the prefix query you need to combine different queries together. You can do that using the bool query. You just need to decide which queries must match, which ones must not match and which ones should match (if they are optional). You can also give a boost to each query in order to express that prefix matches are more important for example.

    On the other hand, if you decide to index EdgeNGrams you can use a single query string and search on different fields giving a different weight to them, like this:

    {
        "query" : {
            "query_string" : {
                "fields" : "user.ngrams^3 field1^2 field2",
                "query" : "query"
            }
        }
    }
    

    You also need to take into account that the query string allows you to search for multiple terms (a boolean query is generated out of them) and to use the lucene query syntax. Also, the query string is analyzed while the prefix query is not. It all depends on what you need and whether those features are useful for your usecase.

    Let me know if you need more information.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very basic API in my app which also has an index
I have a very basic question about PHP. So, there is index.php that includes
I have a very basic mysql table called memberships, that tracks which people belong
I have some very basic semaphore code that works great on Linux, but cannot
I have a very basic doubt regarding the method that gets executed when app
I have a very basic data class that is subclassed from NSObject. I declare
I have a very basic node script that starts up, serving up an html
I currently have a very basic JQuery script accompanied by some CSS that helps
I have a very basic windows forms app, working in C#, and I was
I have a very basic app with two ignition-remoteimageviews (RIV) in them. The app

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.