0
votes

I want to perform both exact word match and partial word/sub string match. For example if I search for "test product" then I should be able to find "test" and "product" related text in the result. Am searching elastic search with the below match query, which is not giving me the exact match instead its giving some more irrevalant match also.Example it's give "sample" related text in the result.

am using elastic search 6.3

Please find my query below

GET /_search { "must":{ "query_string":{ "query":"title:test product" } } }

Search Result: "hits": [ { "_index": "67107104", "_type": "_doc", "_id": "1", "_score": 0.6931471, "_source": { "title": "testing" } }, { "_index": "67107104", "_type": "_doc", "_id": "2", "_score": 0.6931471, "_source": { "title": "product good" } }, { "_index": "67107104", "_type": "_doc", "_id": "3", "_score": 0.6931471, "_source": { "title": "sample" } } ]

Expected Search Result:

"hits": [ { "_index": "67107104", "_type": "_doc", "_id": "1", "_score": 0.6931471, "_source": { "title": "testing" } }, { "_index": "67107104", "_type": "_doc", "_id": "2", "_score": 0.6931471, "_source": { "title": "product good" } } ]

1
what is your expected search result ?ESCoder
Expected seach result "hits": [ { "_index": "67107104", "_type": "_doc", "_id": "1", "_score": 0.6931471, "_source": { "title": "testing" } }, { "_index": "67107104", "_type": "_doc", "_id": "2", "_score": 0.6931471, "_source": { "title": "product good" } } ]revathi

1 Answers

0
votes

In the search query above, you are searching in the review field, whereas in the search result you are getting data for title field

Adding a working example with index data, search query, and search result

Index Data:

{
  "review": "testing"
}
{
  "review": "product good"
}
{
  "review": "sample"
}

Search Query:

{
  "query": {
    "match": {
      "review": "test product"
    }
  }
}

Search Result:

 "hits": [
  {
    "_index": "67119314",
    "_type": "_doc",
    "_id": "2",
    "_score": 0.2876821,
    "_source": {
      "review": "product good"
    }
  }
]