Facing issue while exact match


(Gautam Vanani) #1

Hi I'm trying to do exact match using filter, but it is not returning expacted result,
in result scrore is 0 but still it is returning documents by matching some words given in match query,

below is query:

GET history/saved_search/_search
{
  "_source": "saved_search_name", 
  "query": {
    "bool": {
      "filter": {
        "bool": {
          "must": [
            {
              "match": {
                "login_name": "superman"
              }
            },
            {
              "match": {
                "saved_search_name": "Low quality clothes"
              }
            }
          ]
        }
      }
    }
  }
}

getting this as result

"hits": {
    "total": 2,
    "max_score": 0,
    "hits": [
      {
        "_index": "history",
        "_type": "saved_search",
        "_id": "AVv2tSUeWjRMtjG_6lOM",
        "_score": 0,
        "_source": {
          "saved_search_name": "Our preferred clothes"
        }
      },
      {
        "_index": "history",
        "_type": "saved_search",
        "_id": "AVv2rdFJWjRMtjG_6lOK",
        "_score": 0,
        "_source": {
          "saved_search_name": "Quality clothes with."
        }
      }
    ]
  }

this is setting of the index

{
  "history": {
    "aliases": {},
    "mappings": {
      "saved_search": {
        "properties": {
          "login_name": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "party_id": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "saved_search_name": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
      }
    },
    "settings": {
      "index": {
        "creation_date": "1493373943740",
        "number_of_shards": "5",
        "number_of_replicas": "1",
        "uuid": "QDDPk5EuQR-8IgUDv33UeA",
        "version": {
          "created": "5030199"
        },
        "provided_name": "history"
      }
    }
  }
}

Can any one help to solve this?
Thanks in advance


(venkatreddy amalla) #2

For exact match type queries use term query instead of match. Replace your field names in queries with their respective .keyword form e.g replace saved_search_name with saved_search_name.keyword


(Gautam Vanani) #3

@avr Thank you for response.
It works and if I'm using .keyword with match than it is also working fine.

Can you please explain how it works?


(system) #4

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