1

I want to display only the items that contain the word itself when "google" searches How can I only search for items that have only the word "google"?

Request body (Request created in postman)

{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "body": "google"
          }
        }
      ]
    }
  }
}

Response body (Request created in postman)

{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 3,
      "relation": "eq"
    },
    "max_score": 0.6587735,
    "hits": [
      {
        "_index": "s_t",
        "_type": "_doc",
        "_id": "3",
        "_score": 0.6587735,
        "_source": {
          "body": "google"
        }
      },
      {
        "_index": "s_t",
        "_type": "_doc",
        "_id": "4",
        "_score": 0.5155619,
        "_source": {
          "body": "google map"
        }
      },
      {
        "_index": "s_t",
        "_type": "_doc",
        "_id": "5",
        "_score": 0.5155619,
        "_source": {
          "body": "google-map"
        }
      }
    ]
  }
}

I need this output (Request created in postman)

{
  "took": 2,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 3,
      "relation": "eq"
    },
    "max_score": 0.69381464,
    "hits": [
      {
        "_index": "s_t",
        "_type": "_doc",
        "_id": "3",
        "_score": 0.69381464,
        "_source": {
          "body": "google"
        }
      }
    ]
  }
}

In mysql with this query I reach my goal.

Similar query in mysql:

select * from s_t where body='google'
  • Please do **not** post code as images - use formatted text. See here for more details why: http://meta.stackoverflow.com/questions/285551 –  Feb 19 '20 at 08:18

1 Answers1

0

well i assume you automap or use a text in your mappings. specify .keyword in your query. Note this is case sensitive.

{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "body.keyword": "google"
          }
        }
      ]
    }
  }
}

If you only want to query your body field using exact match. You need to reindex it using keyword. Take a look at: Exact match in elastic search query

LeBigCat
  • 1,737
  • 1
  • 11
  • 16