Elasticsearch Completion Consultant, Custom Order

Is there a way to achieve custom ordering in the Elasticsearch Completion Expert function without providing a separate field containing the weight attribute when indexing?

My goal is to sort sentences by line length (or similar relevance) so that shorter words are taller than longer words.

Here is an example of a field mapping on which I want to provide an autocomplete feature:

...
skills: {
  type: "nested", 
  include_in_parent: true, 
  properties: {            
    name: {
      type: "multi_field",
      fields: {
        name: {type: "string"},
        original: {type : "string", analyzer : "string_lowercase", include_in_all : false},                   
        suggest: {type: "completion", index_analyzer: "simple", search_analyzer: "simple"}
      }              
    }
  }
}
...

      

Here I provide several different fields, the "original" field is for filtering in requests, the "suggest" field is used for the completion expert.

My data when indexed might look like this:

...
"skills": [
  {
     "name": "C",
     "source": [
        "linkedin"
     ]
  },
  {
     "name": "Computer Science",
     "source": [
        "stackoverflow"
     ]
  },
]
...

      

What I'm trying to avoid is to provide an extra field when indexing and adding weighting for this, like:

...
"skills_suggest": [
  {
    "input": ["C"],
    "output": "C",
    "weight" : 100
  },
  {
    "input": ["Computer Science"],
    "output": "Computer Science",
    "weight" : 50
  }
]
...

      

I am trying to do this because I am using the autocomplete feature in the search box in my application. I am showing the top 10 hits in the dropdown below the search box. My problem is that I have so many skills to choose from that when I type the letter "C" the actual skill, which is the programming language "C", scores lower than the longer words and therefore does not appear in my drop down menu to the top ten.

+3


source to share





All Articles