1

I am using following elasticsearch query which I created using POST /_search/template/search through Postman

{
    "template": {
  "query": {
    "bool": {
      "should": [
        {
          "nested": {
            "path": "paymentAccounts",
            "query": {
              "bool": {
                "should": [
                  {
                    "nested": {
                      "path": "accounts",
                      "query": {
                        "bool": {
                          "should": [
                           {
                             "wildcard": {
                              "accounts.person.email.keyword": "*{{smartsearchquerystring}}*"
                              }
                            },
                            {
                              "wildcard": {
                                "accounts.description.keyword": "*{{smartsearchquerystring}}*"
                              }
                            },
                            {
                              "wildcard": {
                                "accounts.tradeName.keyword": "*{{smartsearchquerystring}}*"
                              }
                            },
                            {
                              "wildcard": {
                                "accounts.referenceId.keyword": "*{{smartsearchquerystring}}*"
                              }
                            }
                          ]
                        }
                      }
                    }
                  }
                ]
              }
            }
          }
        }
      ]
    }
  },
"from" : "{{offset}}",
"size" : "{{limit}}"
}
}

Now each time if I want to update the search template I hit the same endpoint through Postman. I want to create a method in my service such as whenever I want to update that any template just gives params to that method and create or update the template.

How can I do that using Java? or any suggestions regarding this.

M Pankaj Arun
  • 84
  • 1
  • 8

1 Answers1

0

You have to save your template as JSON somewhere and send a PUT request to ES, and your Endpoint should be like below, not the one you used to search: /_template/{{template name or alias}}

you can use OkHttpClient to send your request more details check below: OKhttp PUT example

AMA
  • 408
  • 3
  • 9