Elasticsearch sorting the data by using keywords

Fenix Lam

I am a noobie in elasticsearc.

Recently I am doing a research for the keyword search. I already done a version for the mysql with php. But I don't have idea how to do it in elasticsearch by using its default functions.

Here is the data format:

[{"id":"1","keyword":["A","B"]},
 {"id":"2","keyword":["A","C"]}
] 

Basically those keywords work as hashtag for searching to find out the data. And I had to take the most keyword hits in the records and sort them according to how many keyword they got hit.

In this example, if I input "A B" for searching in this example, I will get the result as:

[{"id":"1","id":"2"}]

id 1 record hits two keywords and become the first record in the ordering, id 2 record hits only one keyword and become the second record.

How can I do it in Elasticsearch?

user3775217

Try this query

{
    "query": {
        "match": {
            "keyword": "A B"
        }
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related