0

Example 1: My query term is "abcd".

My query structure is like this:

    query: {
       query_string: {
          query: "abc",
          fields: ["field1", "field2", "field3"]
       }
    },
    size: 50,
    "highlight": {
    "fields": {
        "field1": {},
        "field2": {},
        "field3": {}
    }

It matches the following instances:

abc abcs abc_def_ghi

But it does not match def_abc or def_abc_ghi. Basically instances where abc is in the middle of a string.

Example 2: In the same example above, if my query is abc_def

It does not match abc_def_ghi, although abc_def is present.

I have tried prefix_phrase and it solves scenario 2 but misses out on example 1's problems.

Any help would be appreciated.

1_0
  • 15
  • 1
  • 7

2 Answers2

0

for these usages you should use wildcard in query or regular expression

if you are using term query you can utilize wildcard term query or regexp query instead.

0
  • As name suggests phase_prefix is like poor mans autocomplete it searches for fields which starts with given phrase in your case abc,abcs,abc_def_ghi. as your field doesn't start with abc in case of def_abc,def_abc_ghi it won't work with phrase prefix.
  • Try using character filters specifically Pattern Replace Character Filter to replace _ with (space) from your field while analyzing your field. check this answer . so your token would result in [def,abc,ghi] instead of single token like [def_abc_ghi]. then you can search it using cross_field on analyzed field which should satisfy all of your mentioned cases.
Akash Patel
  • 190
  • 1
  • 10