elasticsearch


Elasticsearch: restrict result to documents with exact match


Currently I trying to restrict results of Elasticsearch (5.4) with the following query:
{
"query": {
"bool": {
"must": {
"multi_match": {
"query": "apache log Linux",
"type": "most_fields",
"fields": [
"message",
"type"
]
}
},
"filter": {
"term": {
"client": "test"
}
}
}
}
}
This returns every document that contains "apache", "log", or "linux". I want to restrict the results to documents that have a field "client" with the exact specified value, this case: "test". However, this query returns all the documents that contain "test" as value. A document with "client": "test client" will also be returned.
I want to restriction to be exact, so only the documents with "client": "test" should be returned and not "client": "test client".
After testing a bunch of different queries and lots of searching, I can not find a solution to my problem. What am I missing?
Just use the keyword part of your client field, since this is 5.x and, by default, the keyword is already there:
"filter": {
"term": {
"client.keyword": "test"
}
}
Set a mapping on your index specifying that your client field is a keyword datatype.
The mapping request could look like
PUT my_index
{
"mappings": {
"my_type": {
"properties": {
"client": {
"type": "keyword"
}
}
}
}
}

Related Links

Why does kibana 3.x not work with elastic search 2.x?
Retrieving top terms query in Elasticsearch
Elastic Search filter by count of a nested document
Elasticsearch - using ngrams as a tokenizer and filter gives different outputs
Grouping match_phrase search results by match text in Elastic Search
Need a customized index in the elasticsearch
ElasticSearch assign own IDs while indexing with LogStash
How to retrieve the latest event with a given field value?
Converting nginx access log bytes to number in Kibana4
Elasticsearch minBy
Snowball analyzer vs language analyzer
AND between tokens in elasticsearch
Elasticsearch Stemmer Override Token Filter not working when usind rules path
Logstash extracting values from sp_executesql
Logstash Grok Modifying and overwriting #timestamp
how to restore elasticsearch.yml config file to original?

Categories

HOME
hpoo
elasticsearch
couchdb
biztalk
tibco
share
firebase-database
save
minecraft
tup
msmq
migrate
jquery-select2-4
createjs
async-await
android-contacts
cocos2d-android
node-webkit
backtracking
device
cell
software-packaging
function-points
fstar
sap-lumira
points
macromedia
ibm-connections
es6-modules
infopath2010
windowsiot
steam-web-api
snap-framework
actframework
shapeless
devtools
dreamfactory
assert
python-sounddevice
praat
ejml
minikube
web-inspector
latexml
permission-denied
audio-converter
datediff
rcharts
ogg
tablespace
system.net.mail
qtcpsocket
eclemma
node.js-connect
distributed-cache
verisign
teamviewer
seadragon
ajax4jsf
boost-proto
css-paged-media
360-degrees
supersocket.net
roxygen2
embeddedwebserver
quercus
debug-symbols
siena
windows-messages
mfmessagecomposeview
thruway
principalcontext
meteorite
infinite
dibs
ofstream
cgrectmake
idispatch
pageheap
image-scanner
dropshadow
mvcrecaptcha
startupscript
kext
self-tracking-entities
3270
chronic

Resources

Encrypt Message