elasticsearch


Exact (not substring) matching in Elasticsearch


{"query":{
"match" : {
"content" : "2"
}
}} matches all the documents whole content contains the number 2, however I would like the content to be exactly 2, no more no less - think of my requirement in a spirit of Java's String.equals.
Similarly for the second query I would like to match when the document's content is exactly '3 3' and nothing more or less. {"query":{
"match" : {
"content" : "3 3"
}
}}
How could I do exact (String.equals) matching in Elasticsearch?
Without seeing your index type mapping and sample data, it's hard to answer this directly - but I'll try.
Offhand, I'd say this is similar to this answer here (http://stackoverflow.com/a/12867852/382774), where you simply set the content field's index option to not_analyzed in your mapping:
"url" : {
"type" : "string",
"index" : "not_analyzed"
}
Edit: I wasn't clear enough with my original answer, shown above. I did not mean to imply that you should add the example code to your query, I meant that you need to specify in your index type mapping that the url field is of type string and it is indexed but not analyzed (not_analyzed).
This tells Elasticsearch to not bother analyzing (tokenizing or token filtering) the field when you're indexing your documents - just store it in the index as it exists in the document. For more information on mappings, see http://www.elasticsearch.org/guide/reference/mapping/ for an intro and http://www.elasticsearch.org/guide/reference/mapping/core-types/ for specifics on not_analyzed (tip: search for it on that page).
Official Doc
You should use filter instead of match.
{
"query" : {
"constant_score" : {
"filter" : {
"term" : {
"content" : 2
}
}
}
}
And you got docs whose content is exact 2, instead of 20 or 2.1

Related Links

Spring Data ElasticSearch - cannot connect to node
How to reverse search given a new document in the query in elasticsearch?
ElasticSearch Failed to create index
difference between field and term query or match query
Cluster Block Exception on Elasticsearch
Elasticsearch query for sum of part of a document
how does the logstash kv{} feature work?
Logstash ruby filter conditional statement error
How to change index field as not analyzed in elastic search while writing a dataframe?
What is the theory behind, Elasticsearch indexing the unstructured data like pdf files?
What database can be used with ElasticSearch [closed]
Docker-compose - volumes driver local meaning
How can I delete my entire Elasticsearch db and resend all the logs?
How to configure the publish address of elasticsearch 5.0 with CLI flags?
How to limit ngram tokenzier to first few characters to make it behave like sliding edgeNgram?
nest : how do an index mapping by passing a raw request?

Categories

HOME
focus
subdomain
web2py
bellman-ford
azure-graph-api
solution
getopenfilename
parsley.js
feature-extraction
stimulsoft
async-await
user-defined-types
word2vec
boomi
salt-cloud
codefluent
nullreferenceexception
spyder
connection-refused
pymongo
mime-types
dragula
nurbs
password-generator
fatfs
d3.js-v4
xenapp
snap-framework
xcrun
xmlunit
nest
gnu-classpath
pdfminer
love2d
twilio-php
tidal-scheduler
assert
grunt-contrib-watch
python-jira
grails-spring-security
classnotfoundexception
secure-coding
robust
access-denied
autorelease
datediff
android-sharing
line-intersection
nslayoutconstraint
glassfish-4.1
glimpse
lvalue
zend-server
emf-compare
openerp-6
oracle-fusion-apps
logical
dpkg
meld
strpos
mnesia
gulp-uglify
mousehover
calcite
screen-orientation
auto-generate
supercomputers
360-degrees
postal-code
libz
modern.ie
scala-macros
quercus
fuseesb
createfile
flurry-analytics
device-admin
multivariate-testing
code-complexity
fileshare
air-native-extension
django-settings
mft
illuminate-container
xsd2code
ldif
ofstream
android-authenticator
idispatch
sfinae
drawimage
qt-mobility
office-automation
database-deadlocks
printqueue
formal-semantics
downgrade
eaccelerator
mongrel
uninstaller
downloadfile

Resources

Encrypt Message