Query with Text field

I have index settings and mappings are as below
"settings": {
"number_of_shards": 1,
"number_of_replicas": 1,
"index": {"max_result_window": 10000000, "max_inner_result_window": 1000},
"analysis": {
"analyzer": {
"custom_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": ["lowercase", "stop", "asciifolding"],
"char_filter": ["html_strip"],
},
"sort_analyzer": {
"type": "custom",
"tokenizer": "keyword",
"filter": ["lowercase", "asciifolding"],
"char_filter": ["html_strip"],
},
}
},
},

"mappings": {
"dynamic": "strict",
"properties": {
"uuid": {"type": "keyword"},
"task_number": {"type": "integer"},
"task": {
"type": "text",
"fields": {"keyword": {"type": "keyword"}},
"analyzer": "sort_analyzer",
"fielddata": True,
}
}

"task" : " Test User Data"
now I need to create a search query where if the user search "ser" it can see this above string but if user added "Test User Data Test User Data" it won't be able to see the result

Hi Kunjal,

Welcome to the community! Thanks for sharing your mapping and settings. Can you give more details on what fields the search terms are to be applied to?

I'm not quite clear what search you are trying to do. But I assume you want to include documents based on one criteria and exclude based on another, which would fit well with a bool query, such as this:

GET santas-playlist/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "title":  "christmas"
          }
        }
      ],
      "must_not": [
        {
          "match_phrase": {
            "artist": "Chris Rea"
          }
        }
      ]
    }
  }
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.