How in elasticsearch do a search for several words working in case the words stand not together?


(Sergei Kurbako) #1

How in elasticsearch do a search for several words working in case the words stand not together?


(Adrien Grand) #2

Sorry I don't understand the question, can you explain a bit more what you want to know?


(Sergei Kurbako) #3

I have bad English, sorry :slight_smile: . I will explain with an example:

In the elastic there are three records:
query 1: Simple Token Coin
query 2: Token Simple Coin
query 3: Coin Token Simple

serch request:
Simple Token

I have to send a request and get these three lines

My php code with the following parameters does not work:

$params = [
        'index' => 'myapp',
        'type' => 'post',
        'size' => 10,
        'from' => 10,
        'body' => $json
        'body' => [
            'query' => [
                'match_phrase_prefix' => [
                    'post_title' => [
                        "query" => $_POST['test'],
                        'analyzer' => 'russian',
                    ]
                ]
            ],
            'sort' => [
                'post_title' => [
                    'order' => 'DESC'
                ]
            ]
        ]
    ];

I need the right options :slight_smile: or correct actions ...
Maybe I need an analyzer, but I do not understand how to create and apply it


(Cameron Eby) #4

You want to use the queryString query method and set the phrase slop to a value high enough to accommodate all groups of characters(words) that are stored in that field. Quick Red Fox, has 3 positions, right, set slop to 1 would ensure that someone doing a search for 'quick fox' gets a hit. The slop is the number of positions that words need to 'move' to be adjacent to any other. That's how I picture it anyway. 'Quick red' would match with a slop of 0 (default) because the words are already adjacent. In my case I have fields that could consist of 8-10 "words" so I set my slop to high enough for worst case scenarios where the queried string happens to be the first word and the last word in the field. If a field had the value 'The quick red fox jumps over the lazy men.' If the search string was "quick lazy" the slop would need to be set to at least 6 because 'quick' would have to move 6 positions in order to be adjacent to 'lazy.'


(system) #5

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.