Home > Back-end >  Elasticsearch, how to get a search result in all circumstances
Elasticsearch, how to get a search result in all circumstances

Time:12-07

I've been dealing with a project. My goal is to get result from search engine in all circumstances for example, although i enter a keyword which is not include the keys inside data or is a empty string, I still need to get some result.How can i reach my goal?

you can see the query below :

  query: {
          regexp: {
            title: "something to not found .*",
          },

CodePudding user response:

Try use "prefix" or "query_string"

You also can use title.keyword for exact value

1 - 
{
  "query": {
    "prefix": {
      "title": {
        "value": "<data>"
      }
    }
  }
}

2 - 
{
  "query": {
    "query_string": {
      "default_field": "title",
      "query": "<data>*^0"
    }
    
  }
}
  • Related