must match query not working as expected in Elasticsearch

Fisher Coder

I've created my index below using Kibana which connected to my AWS ES domain:

PUT sals_poc_test_20210217-7
{
    "settings" : {
      "index" : {
        "number_of_shards" : 10,
        "number_of_replicas" : 1,
        "max_result_window": 50000,
        "max_rescore_window": 50000
      }
    },
    "mappings": {
      "properties": {
        "identifier": {
          "type": "keyword"
        },
        "CLASS_NAME": {
          "type": "keyword"
        },
        "CLIENT_ID": {
          "type": "keyword"
        }
      }
    }
}

then I've indexed 100 documents, using below command returns all 100 documents:

POST /sals_poc_test_20210217-7/_search
{
  "query": {
    "match": {
      "_index": "sals_poc_test_20210217-7"
    }
  }
}

two sample documents are below:

{
        "_index" : "sals_poc_test_20210217-7",
        "_type" : "_doc",
        "_id" : "cd0a3723-106b-4aea-b916-161e5563290f",
        "_score" : 1.0,
        "_source" : {
          "identifier" : "xweeqkrz",
          "class_name" : "/Sample_class_name_1",
          "client_id" : "random_str"
        }
      },
{
        "_index" : "sals_poc_test_20210217-7",
        "_type" : "_doc",
        "_id" : "cd0a3723-106b-4aea-b916-161e556329ab",
        "_score" : 1.0,
        "_source" : {
          "identifier" : "xweeqkra",
          "class_name" : "/Sample_class_name_2",
          "client_id" : "random_str_2"
        }
      }

but when I wanted to search by CLASS_NAME by below command:

POST /sals_poc_test_20210217-7/_search
{
  "size": 200,
  "query": { 
    "bool": { 
      "must": [ 
        { "match": { "CLASS_NAME": "/Sample_class_name_1"}}
      ]
    }
  }
}

Not only the documents that match this class_name returned, but also other ones.

Anyone could shed any light into this case please?

I'm suspecting the way I wrote my search query is problematic. But cannot figure out why.

Thanks!

Balu Vyamajala

Elastic search, is case sensitive. class_name is not equal to CLASS_NAME sample documents seems to have class_name but mapping in index seems to have 'CLASS_NAME.

If we GET sals_poc_test_20210217-7, both class name attributes should be in the index mapping. The one when creating the index and second one created when adding documents to index.

so, query should be on CLASS_NAME or class_name.keyword , by default elastic search creates both text and .keyword field for dynamic attributes

    "CLASS_NAME" : {
      "type" : "keyword"
    },

    "class_name" : {
      "type" : "text",
      "fields" : {
        "keyword" : {
          "type" : "keyword",
          "ignore_above" : 256
        }
      }
    }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

must match query not working as expected in Elasticsearch

From Dev

match_query is not working in elasticsearch

From Dev

Using bool must match and match _all in one elasticsearch query

From Dev

elasticsearch search query for exact match not working

From Dev

elasticsearch search query for exact match not working

From Dev

In elasticsearch, must match one of array, with optional extra query term

From Dev

Elasticsearch must_not query doesn't match regex

From Dev

elasticsearch synonyms not working as expected

From Dev

Elasticsearch mapping not working as expected

From Dev

elasticsearch must query combine OR?

From Dev

preg match not working as expected

From Dev

Couchbase Query not working as expected

From Dev

LIKE query not working as expected

From Dev

Bool query not working as expected

From Java

elasticsearch bool query combine must with OR

From Dev

Combining must_not in ElasticSearch Query

From Dev

Pattern match not working as expected python

From Dev

preg_match is not working as expected

From Dev

Elasticsearch filtered query not working

From Dev

Elasticsearch filtered query not working

From Dev

Elasticsearch: Filter Query not working

From Dev

Elasticsearch query with date not working

From Dev

Elasticsearch query results in 'No query registered for [must]'

From Java

Firestore "where" query not working as expected

From Dev

Relation field query not working as expected

From Dev

Media Query in CSS Not working as expected

From Dev

mysql_query is not working as expected

From Dev

Yii update query not working as expected

From Dev

Query not working as expected in stored procedure

Related Related

HotTag

Archive