2

enter image description here

I want to use the elastic search to query documents who has the matching values of "dc883c6f24776ad6ce1f86c41b5cf87cfb784e85".

Please find the structure of the source document attached in the image. Is it possible to query this with something like below using *[wild char] when the field name is unknown for us.

 "query" : {
    "constant_score" : {
        "filter" : {
            "terms" : { 
                "commitId.persistence-statics-service.*":["dc883c6f24776ad6ce1f86c41b5cf87cfb784e85"]
            }
        }
    }
}
eablex
  • 59
  • 5

2 Answers2

2

You can use query_string or multi_match to specify a wildcard in the field name part. I think the multi_match is simpler though:

{
  "query": {
    "constant_score": {
      "filter": {
        "multi_match": {
          "query": "dc883c6f24776ad6ce1f86c41b5cf87cfb784e85",
          "fields": [
            "commitId.persistence-statics-service.*"
          ],
          "analyzer": "keyword"
        }
      }
    }
  }
}
Andrei Stefan
  • 51,654
  • 6
  • 98
  • 89
2

Try to Use query_string . Its very powerful in partial search in ES ,check my answer link :-

{
  "query": {
    "query_string": {
       "fields" : ["commitId.persistence-statics-service.*"] ,
      "query": "*dc883c6f24776ad6ce1f86c41b5cf87cfb784e85*"
    }
  }
}

Query_string is more powerful than multi_match link2

Community
  • 1
  • 1
Vijay
  • 4,694
  • 1
  • 30
  • 38