I have a multi_field mapping:
"testMulti": {
"type": "multi_field",
"fields": {
"testMulti": {
"type": "string",
"index": "analyzed",
"analyzer": "english"
},
"exact": {
"type": "string",
"index": "not_analyzed"
}
}
}
I would like to use testMulti.exact field for exact match and also for substring exact match.
If the field contains:
"There is a dog"
it will be returned for:
"query_string": {
"query": ""is a dog"",
"fields": [
"testMulti.exact"
]
}
}
and also for "query": ""There is"" and not for "query": ""Is a dog"", "query": ""are a dog"", etc...
The document is returned only for a full match: "query": ""There is a dog"", and not part match.
This is an interesting problem. Typically, my view of stop words is dim. I
would prefer that the client side avoids searching on them if that is
desired, rather than the engine ignores them. Then, phrase matching can
work properly. And queries such as The Wall can look for just Wall(ignoring
The as a stop word), but then the Google-like +The Wall can look for The
Wall. Yeah, I know that ES is not Google; I only look to Google for ideas
that are nice and for hints about their implementation based upon their
external behavior.
Then, your problem could be solved using a phrase query with no slop.
Maybe your testMulti field is analyzed but no stop words are ignored. Or,
maybe testMulti.raw is analyzed but with no stop words ignored. Either way,
you'd have the full set of words indexed for a phrase query to quickly find
the sub-match. At least, much, much more quickly than a grep-style wildcard
search against a non-analyzed form of the field.
I also used phrases within my own table-based synonym matching. Instead of
using ES synonyms, I create a separate type with lists of synonyms. A query
for a synonym is first directed to that type to fetch a list of synonyms;
then an OR query is generated. This has proven to be fast enough. It has
the benefit of allowing the synonyms to be updated with no changes to the
97-millon documents that are already indexed. And, synonyms can be phrases,
for example: HUGE -> "VERY BIG". So now a synonym query for HUGE can find The
Very Big Dog. Likewise, a synonym query for the phrase "VERY BIG" can find The
Huge Dog. Really cool; just a matter of Java coding on the front end. And
ES does the heavy lifting underneath. But I digress a little...
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.