0

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?

1 Answer 1

1

Try this query

{
    "query": {
        "match": {
            "keyword": "A B"
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.