Different Query format for wildcard query and term query

Hey community, I am currently using below mentioned query format for term query

{
  "query": {
    "term": {
      "core.externalId": "Kimchy"
    }
  }

Below is the query format described in Elasticsearch Document Term query | Elasticsearch Guide [8.5] | Elastic

{
  "query": {
    "term": {
      "user.id": {
        "value": "kimchy"
      }
    }
  }
}

I am planning to implement same format for wildcard query as well which have similar differences as Term query in comparison to Elasticsearch Document

What I am implementing
<fieldName> : <value>

Elasticsearch document query format

<fieldName> : {
"value": <value>
}

I have tried these two query formats directly on Elasticsearch and both of these are working fine.

Attaching wildcard Query examples that I have tried directly on Elasticsearch –
Request

{
  "query": {
    "wildcard": {
      "core.ext::keyword": "Di*ionary"
    }
  }
}

Response

{
    "took": 2,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 3,
            "relation": "eq"
        },
        "max_score": 1.0,
        "hits": [
            {
                "_index": "adholpuria",
                "_type": "_doc",
                "_id": "xxxxxxxx",
                "_score": 1.0,
                "_source": {
                    "core.name::text": "Reading",
                    "core.ext::keyword": "dictionary"
                }
            },
            {
                "_index": "adholpuria",
                "_type": "_doc",
                "_id": "xxxxxxxxx",
                "_score": 1.0,
                "_source": {
                    "core.name::text": "Reaping",
                    "core.ext::keyword": "dicpionary"
                }
            },
            {
                "_index": "adholpuria",
                "_type": "_doc",
                "_id": "xxxxxxxx",
                "_score": 1.0,
                "_source": {
                    "core.name::text": "Reamding",
                    "core.ext::keyword": "dicmtionary"
                }
            }
        ]
   }
}

I am looking for supportive doc. But couldn't find one. Do e have any supportive document for <fieldName> : <value> query format. Is there any possibility that earlier Elasticsearch has
<fieldName> : <value> query format for term query and wild card query but now it is depricated?

Thanks

Hi Abhijeet,

To confirm, are you looking for the documentation for the wildcard terms query, but specifically the "field": "value" form? I see an example in the terms query documentation, but not in the wildcard one. As these are both term type queries they should work in a similar way.

Not sure which version of Elasticsearch you are using, but having a scan through that format for wildcard in prior versions, wildcard with this format has been supported since at least 1.3.

You can use "field": "value" as a shorthand where you don't need any other optional parameters as per the query DSL. Hope that helps!

1 Like

Hey Carly,
yes that helps. Thanks for replying.

1 Like

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