10

The documentation states that the path needs to be a string and not an array of strings. I just want to confirm that that is in fact the only possibility, and if, in either case, there is a recommended way to do this.

e.g. I want to search (with autocompletion) my movies for the text "hammer" on both the title and the plot

In the current scenario I can implement a search by either title or plot with ease. But If I try to do it for both, making path an array of strings, which is acceptable on other operators, I get an error

Rodrigo Sasaki
  • 7,048
  • 4
  • 34
  • 49
  • 2
    https://stackoverflow.com/questions/63186815/create-querystring-search-pipeline-that-returns-result-not-only-by-word-bounda <-- check out that answer. It's the same problem in solution with more data. It should solve your problem.. – Nice-Guy Aug 06 '20 at 20:52

1 Answers1

12

If you are trying to match on title and plot, use should: in compound operator

create autocomplete search index on both fields : title and plot

$search: {
    compound: {
        should: [
            {
                autocomplete: {
                    query:'hammer',
                    path: 'title',
                },
            },
            {
                autocomplete: {
                    query:'hammer',
                    path: 'plot',
                },
            },
        ],
    },
},
Jitendra Patel
  • 121
  • 1
  • 5