How can i perform a search excluding results where a field has a specific value?
I have a database of Reddit comments and i want to find Bitcoin mentions, but exclude the bitcoin subreddit.
curl -s -XGET 'http://localhost:9200/_search?pretty=true&size=100' -d '
{
"filtered": {
"query" : {
"match": {
"body": "bitcoin"
}
},
"filter": {
"not": {
"term": {
"subreddit": "bitcoin"
}
}
}
}
}'
The error is to long to post here. https://gist.github.com/kylelk/feca416156712eebad3e
If a search request results in more than ten hits, ElasticSearch will, by default, only return the first ten hits. To override that default value in order to retrieve more or fewer hits, we can add a size parameter to the search request body.
But if you want to search for all documents containing a null value, you can tell Elasticsearch to replace the null value with a default value. And sometimes the login_status is sent as null by default. If the login_status field is null, the login_status field is skipped.
The _score in Elasticsearch is a way of determining how relevant a match is to the query. The default scoring function used by Elasticsearch is actually the default built in to Lucene which is what Elasticsearch runs under the hood.
It is silly error,
You have to include filtered query inside query . Here is modification
POST _search
{
"query": {
"filtered": {
"query": {
"match": {
"body": "bitcoin"
}
},
"filter": {
"not": {
"term": {
"subreddit": "bitcoin"
}
}
}
}
}
}
Hope this helps!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With