Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Need help in writing OpenSearch multi-match query in Java?

  1. #1
    Junior Member
    Join Date
    Feb 2023
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help in writing OpenSearch multi-match query in Java?

    Hi.

    I am using OpenSearch to search text documents. I am using opensearch-java SDK to connect & index documents. I am able to write most of the basic CRUD operations. But I am stuck with writing multi-match query on a long data type. I have two fields avg_salary & max_salary. If anyone of them matches a number (suppose 100), I need to return the documents. Please help me with an example or sample Java code.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need help in writing OpenSearch multi-match query in Java?

    Be glad to help you with any problems with your code. Post it and ask questions about what the problems are.
    This site does not provide code. Try the SO site for code.

    Be sure to wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2023
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help in writing OpenSearch multi-match query in Java?

    Thanks for the reply. I am sharing what I tried. I am trying to write multi match query as below:
    		List<String> fields = new ArrayList<String>();
                    fields.add("avg_salary");
                    fields.add("max_salary");
    		MultiMatchQuery query = new MultiMatchQuery.Builder().fields(fields).query(100)
    				.build();
    But query(100) is giving me compilation error. It only takes String as argument.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need help in writing OpenSearch multi-match query in Java?

    Sorry, I am not familiar with that class and its methods. Could you post references to their online documentation?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Feb 2023
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help in writing OpenSearch multi-match query in Java?

    I found the issue. OpenSearch does not support multi match query on integer fields. Actually OpenSearch supports multi match query only on String fields. That is the reason the argument did not take integer value. I wrote multiple match queries & joined them using OR condition as suggested by this article https://www.w3spot.com/2022/11/how-t...y-in-java.html.

Similar Threads

  1. How to use a query result to match an image resource?
    By SANOZUKE in forum Android Development
    Replies: 3
    Last Post: July 28th, 2014, 09:30 AM
  2. How to use a query result to match an image resource?
    By SANOZUKE in forum What's Wrong With My Code?
    Replies: 0
    Last Post: July 27th, 2014, 03:12 AM
  3. Replies: 1
    Last Post: April 3rd, 2014, 02:11 PM
  4. Java equivalant of Python re.match()
    By gonzalioz in forum Java Theory & Questions
    Replies: 1
    Last Post: October 30th, 2011, 10:25 AM
  5. update query is firing first then insert query
    By salmondavid88 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 8th, 2011, 10:15 AM

Tags for this Thread