Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support Filter in searcher like elasticsearch #2037

Open
liulhdarks opened this issue May 22, 2024 · 1 comment
Open

support Filter in searcher like elasticsearch #2037

liulhdarks opened this issue May 22, 2024 · 1 comment

Comments

@liulhdarks
Copy link

How to implement an elasticsearch-like filter query statement that can query specified fields without calculating scores

{
  "query": { 
    "bool": { 
      "must": [
        { "match": { "title":   "Search"        }},
        { "match": { "content": "Elasticsearch" }}
      ],
      "filter": [ 
        { "term":  { "status": "published" }},
        { "range": { "publish_date": { "gte": "2015-01-01" }}}
      ]
    }
  }
}
@blamoo
Copy link

blamoo commented Jun 11, 2024

use BooleanQuery:
https://pkg.go.dev/github.com/blevesearch/bleve/v2#NewBooleanQuery
there is even an usage example in the docs:

must := NewMatchQuery("one")
mustNot := NewMatchQuery("great")
query := NewBooleanQuery()
query.AddMust(must)
query.AddMustNot(mustNot)
searchRequest := NewSearchRequest(query)
searchResults, err := exampleIndex.Search(searchRequest)
if err != nil {
	panic(err)
}

fmt.Println(searchResults.Hits[0].ID)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants