To add test data:
Post/forum/article/_bulk
{"Update": {"_id": "1"}}
{"Doc": {"title": "This is Java and Elasticsearch blog"}
{"Update": {"_id": "2"}}
{"Doc": {"title": "This is Java Blog"}}
{"Update": {"_id": "3"}}
{"D OC ": {" title ":" This is Elasticsearch Blog "}}
{" Update ": {" _id ": ' 4"}}
{"Doc": {"title": "This is Java, E Lasticsearch, Hadoop Blog "}}
{" Update ": {" _id ":" 5 "}}
{" Doc ": {" title ":" This is Spark Blog "}}
Search for the doc in title that contains Java or elasticsearch, which is not a previous term search, but full text retrieval:
Get/forum/article/_search
{"
query": {"
match": {
"title": "Java Elasticsearch"
}
}
}
If we want to search for a doc that contains Java and contains Elasticsearch, then we can do it:
Get/forum/article/_search
{"
query": {"
match": {
"title": {
"query": "Java Elasticsearch" ,
"operator": "and"
}
}
}
If we want to search for results that contain at least 3 of the Java,elasticsearch,spark,hadoop:
Get/forum/article/_search
{"
query": {"
match": {
"title": {"
query": "Java elasticsearch Hadoop Spark ",
" Minimum_should_match ":" 75% "
}
}
}
}
If you can use BOOL with the following search criteria, should defaults to one that does not match:
Get/forum/article/_search
{"
query": {"bool": {"
should": [
{
"match": {
" Title ":" Java "
}
},
{"
match ": {
" title ":" Elasticsearch "
}
},
{
" Match ": {
" title ":" Hadoop "
}
},
{
" match ": {
" title ":" Spark "
}
}
],
"Minimum_should_match": 3
}
}
In fact, when using the match query above for multi-valued searches, the ES layer automatically converts the match query to the BOOL syntax
For example:
{"
query": {"
match": {
"title": "Java Elasticsearch"}}
}
will be converted into:
Get/forum/article/_search {"Query": {"bool": {"
should": [
{"Term
": {
"title"
: { "Value": "Java"}}
,
{"term": {"
title": {
"value": "Elasticsearch"
}
}
}
]
}
}
}
A key step to note is that the only difference between the two is that match uses the word processing for the search parameters, and if you use the term directly, the search parameters will not be processed