Running a query on text field with Below is my index mapping
{
"users_index": {
"settings": {
"index": {
"provided_name": "users_index",
"number_of_replicas": "1",
"uuid": "IpNHWSiDSbq_SW19STOaEg",
"number_of_shards": "5",
"analysis": {
"filter": {
"searchkick_suggest_shingle": {
"type": "shingle",
"max_shingle_size": "5"
},
"searchkick_index_shingle": {
"type": "shingle",
"token_separator": ""
},
"edcast_word_delimiter": {
"type": "word_delimiter",
"preserve_original": "true"
},
"edcast_edge_ngram_filter": {
"max_gram": "30",
"type": "edge_ngram",
"min_gram": "1"
},
"searchkick_stemmer": {
"type": "snowball",
"language": "English"
},
"searchkick_search_shingle": {
"output_unigrams_if_no_shingles": "true",
"output_unigrams": "false",
"token_separator": "",
"type": "shingle"
},
"searchkick_edge_ngram": {
"max_gram": "50",
"type": "edgeNGram",
"min_gram": "1"
},
"searchkick_ngram": {
"max_gram": "50",
"type": "nGram",
"min_gram": "1"
}
},
"char_filter": {
"ampersand": {
"type": "mapping",
"mappings": [
"&=> and "
]
}
},
"normalizer": {
"normalyzer_case_insensitive": {
"filter": [
"lowercase",
"asciifolding"
],
"type": "custom"
}
},
"analyzer": {
"searchkick_suggest_index": {
"filter": [
"lowercase",
"asciifolding",
"searchkick_suggest_shingle"
],
"type": "custom",
"tokenizer": "standard"
},
"analyzer_case_insensitive": {
"filter": "lowercase",
"tokenizer": "keyword"
},
"searchkick_search": {
"filter": [
"lowercase",
"asciifolding",
"searchkick_search_shingle",
"searchkick_stemmer"
],
"char_filter": [
"ampersand"
],
"type": "custom",
"tokenizer": "standard"
},
"searchkick_autocomplete_search": {
"filter": [
"lowercase",
"asciifolding"
],
"type": "custom",
"tokenizer": "keyword"
},
"searchkick_word_middle_index": {
"filter": [
"lowercase",
"asciifolding",
"searchkick_ngram"
],
"type": "custom",
"tokenizer": "standard"
},
"searchkick_index": {
"filter": [
"lowercase",
"asciifolding",
"searchkick_index_shingle",
"searchkick_stemmer"
],
"char_filter": [
"ampersand"
],
"type": "custom",
"tokenizer": "standard"
},
"searchkick_word_end_index": {
"filter": [
"lowercase",
"asciifolding",
"reverse",
"searchkick_edge_ngram",
"reverse"
],
"type": "custom",
"tokenizer": "standard"
},
"searchkick_word_start_index": {
"filter": [
"lowercase",
"asciifolding",
"searchkick_edge_ngram"
],
"type": "custom",
"tokenizer": "standard"
},
"searchkick_word_search": {
"filter": [
"lowercase",
"asciifolding"
],
"type": "custom",
"tokenizer": "standard"
},
"edcast_sort_analyzer": {
"filter": [
"lowercase"
],
"tokenizer": "keyword"
},
"searchkick_keyword": {
"filter": [
"lowercase"
],
"type": "custom",
"tokenizer": "keyword"
},
"edcast_exact_match_analyzer": {
"filter": [
"lowercase"
],
"tokenizer": "keyword"
},
"edcast_search_analyzer": {
"filter": [
"lowercase",
"edcast_word_delimiter",
"stop",
"stemmer"
],
"tokenizer": "standard"
},
"edcast_prefix_search_analyzer": {
"filter": [
"lowercase",
"edcast_word_delimiter",
"edcast_edge_ngram_filter"
],
"tokenizer": "standard"
},
"searchkick_text_start_index": {
"filter": [
"lowercase",
"asciifolding",
"searchkick_edge_ngram"
],
"type": "custom",
"tokenizer": "keyword"
},
"searchkick_text_middle_index": {
"filter": [
"lowercase",
"asciifolding",
"searchkick_ngram"
],
"type": "custom",
"tokenizer": "keyword"
},
"searchkick_text_end_index": {
"filter": [
"lowercase",
"asciifolding",
"reverse",
"searchkick_edge_ngram",
"reverse"
],
"type": "custom",
"tokenizer": "keyword"
},
"searchkick_search2": {
"filter": [
"lowercase",
"asciifolding",
"searchkick_stemmer"
],
"char_filter": [
"ampersand"
],
"type": "custom",
"tokenizer": "standard"
}
}
},
"creation_date": "1707388619329",
"max_ngram_diff": "55",
"max_shingle_diff": "4",
"version": {
"created": "7170099"
},
"routing": {
"allocation": {
"include": {
"_tier_preference": "data_content"
}
}
}
}
},
"mappings": {
"properties": {
"roles": {
"fields": {
"raw": {
"type": "keyword"
}
},
"type": "text",
"fielddata": true
}
},
"dynamic_templates": [
{
"edcast_string_template": {
"match_mapping_type": "string",
"mapping": {
"type": "text"
},
"match": "*"
}
}
]
},
"aliases": {
"users_staging": {}
}
}
}
Sample Documents indexed
{
"hits": {
"hits": [
{
"sort": [
"active",
1
],
"_type": "_doc",
"_source": {
"roles": [
"Member"
]
},
"_score": 1,
"_index": "edcast_users_staging_20240208103659319",
"_id": "3137231"
},
{
"sort": [
"active",
1
],
"_type": "_doc",
"_source": {
"roles": [
"Member"
]
},
"_score": 1,
"_index": "edcast_users_staging_20240208103659319",
"_id": "3137246"
},
{
"sort": [
"active",
1
],
"_type": "_doc",
"_source": {
"roles": [
"Member"
]
},
"_score": 1,
"_index": "edcast_users_staging_20240208103659319",
"_id": "3137254"
},
{
"sort": [
"active",
1
],
"_type": "_doc",
"_source": {
"roles": [
"Member"
]
},
"_score": 1,
"_index": "edcast_users_staging_20240208103659319",
"_id": "3137255"
},
{
"sort": [
"active",
1
],
"_type": "_doc",
"_source": {
"roles": [
"Member"
]
},
"_score": 1,
"_index": "edcast_users_staging_20240208103659319",
"_id": "3137256"
},
{
"sort": [
"active",
1
],
"_type": "_doc",
"_source": {
"roles": [
"Member"
]
},
"_score": 1,
"_index": "edcast_users_staging_20240208103659319",
"_id": "3137259"
},
{
"sort": [
"active",
1
],
"_type": "_doc",
"_source": {
"roles": [
"Member"
]
},
"_score": 1,
"_index": "edcast_users_staging_20240208103659319",
"_id": "3137260"
},
{
"sort": [
"active",
1
],
"_type": "_doc",
"_source": {
"roles": [
"Member"
]
},
"_score": 1,
"_index": "edcast_users_staging_20240208103659319",
"_id": "3137263"
},
{
"sort": [
"active",
1
],
"_type": "_doc",
"_source": {
"roles": [
"Member"
]
},
"_score": 1,
"_index": "edcast_users_staging_20240208103659319",
"_id": "3137266"
},
{
"sort": [
"active",
1
],
"_type": "_doc",
"_source": {
"roles": [
"Member"
]
},
"_score": 1,
"_index": "edcast_users_staging_20240208103659319",
"_id": "3137267"
},
{
"sort": [
"active",
1
],
"_type": "_doc",
"_source": {
"roles": [
"Member"
]
},
"_score": 1,
"_index": "edcast_users_staging_20240208103659319",
"_id": "3137272"
}
],
"total": {
"relation": "eq",
"value": 54410
},
"max_score": null
},
"_shards": {
"successful": 5,
"failed": 0,
"skipped": 0,
"total": 5
},
"took": 6,
"timed_out": false
}
Query 1: Not Working as expected
{
"query": {
"bool": {
"filter": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"terms": {
"roles": [
"Admin"
]
}
},
{
"bool": {
"must": [
{
"terms": {
"roles": [
"Admin",
"D Member 2",
"D Member 3",
"D Member 4",
"Group Admin",
"H Radmin",
"Influencer Xyz",
"Member",
"Publish Links Article Role",
"Sme",
"Super Admin"
]
}
},
{
"terms": {
"roles": [
"1",
"Admin",
"Check Memebr Roles",
"Collaborator",
"Curator",
"D Member 2",
"D Member 3",
"D Member 4",
"Few Creation",
"G User 1",
"G User 2",
"Group Admin",
"H Radmin",
"Influencer Xyz",
"Member",
"My Role",
"Publish Links Article Role",
"Scorm Card Role",
"Smart Card Collaborators",
"Sme",
"Super Admin",
"Text Card Role",
"Upload Role"
]
}
}
]
}
}
]
}
}
],
"must_not": []
}
},
"must": {
"match_all": {}
}
}
},
"from": 0,
"size": 11,
"track_total_hits": true,
"sort": [
{
"status": {
"order": "asc"
}
},
{
"_score": {
"order": "desc"
}
}
]
}
Gives output as empty even when there are matching documents
{
"hits": {
"hits": [],
"total": {
"relation": "eq",
"value": 0
},
"max_score": null
},
"_shards": {
"successful": 5,
"failed": 0,
"skipped": 0,
"total": 5
},
"took": 5,
"timed_out": false
}