Skip to content

Instantly share code, notes, and snippets.

@djptek
Last active May 27, 2021 16:56
Show Gist options
  • Save djptek/1f0c5ff5c680c8bd9c3e5fb35008e376 to your computer and use it in GitHub Desktop.
Save djptek/1f0c5ff5c680c8bd9c3e5fb35008e376 to your computer and use it in GitHub Desktop.
phrase search vs match_only_text field
PUT test
{
"mappings": {
"properties": {
"match_only_text": {
"type": "match_only_text"
},
"text": {
"type": "text"
}
}
}
}
}
POST test/_doc
{
"text": "this is a phrase in a text field"
}
POST test/_doc
{
"match_only_text": "this is a phrase in a match_only_text field"
}
GET test/_search?filter_path=hits.total.value,**.*score
{
"query": {
"match_phrase": {
"text": "this is a phrase"
}
}
}
# {
# "hits" : {
# "total" : {
# "value" : 1
# },
# "max_score" : 1.1507283,
# "hits" : [
# {
# "_score" : 1.1507283
# }
# ]
# }
#}
GET test/_search?filter_path=hits.total.value,**.*score
{
"query": {
"span_first": {
"match": {
"span_term": { "text": "phrase" }
},
"end": 5
}
}
}
#{
# "total" : {
# "hits" : {
# "value" : 1
# },
# "max_score" : 0.2876821,
# "hits" : [
# {
# "_score" : 0.2876821
# }
# ]
# }
#}
GET test/_search?filter_path=hits.total.value,**.*score
{
"query": {
"span_first": {
"match": {
"span_term": { "match_only_text": "phrase" }
},
"end": 5
}
}
}
#{
# "error" : {
# "root_cause" : [
# {
# "type" : "query_shard_exception",
# "reason" : "failed to create query: Cannot extract a term from a query of type class org.apache.lucene.search.ConstantScoreQuery: ConstantScore(match_only_text:phrase)",
# "index_uuid" : "Z0IEhK0fTJSOuBNB2QU1dQ",
# "index" : "test"
# }
# ],
# "type" : "search_phase_execution_exception",
# "reason" : "all shards failed",
# "phase" : "query",
# "grouped" : true,
# "failed_shards" : [
# {
# "shard" : 0,
# "index" : "test",
# "node" : "MsUqU0H6Toqgw_bsoU92nQ",
# "reason" : {
# "type" : "query_shard_exception",
# "reason" : "failed to create query: Cannot extract a term from a query of type class org.apache.lucene.search.ConstantScoreQuery: ConstantScore(match_only_text:phrase)",
# "index_uuid" : "Z0IEhK0fTJSOuBNB2QU1dQ",
# "index" : "test",
# "caused_by" : {
# "type" : "illegal_argument_exception",
# "reason" : "Cannot extract a term from a query of type class org.apache.lucene.search.ConstantScoreQuery: ConstantScore(match_only_text:phrase)"
# }
# }
# }
# ]
# },
# "status" : 400
#}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment