How to write elasticsearch multiple query condition?

Dixit Sourav

I have stored some data in elasticsearch module and structure is very simple.

[
   {
      "country_id":1,
      "city_id":12,
      "city_name":"Kolkata"
   },
   {
      "country_id":1,
      "city_id":55,
      "city_name":"Delhi"
   },
   {
      "country_id":2,
      "city_id":18,
      "city_name":"Las Vegas"
   },
   {
      "country_id":3,
      "city_id":22,
      "city_name":"Sydney"
   }
]

I need a search query like

"Select * from table_name where country_id = 1 and city_name like %k%"

If any one there please help me to find out the exact elasticsearch query for the above sql query.

I have tried with this query but it is producing errors.

curl -XGET "http://xxx.xxx.xxx.x:9200/xxxx/location_details/_search?size=10" -d '{"query":{"bool":{"must":{"term":{"country_id":"101"}}},{"match_phrase":{"city_name":"a"}}}}'
Val

That's a good start

Try this instead:

curl -XPOST "http://xxx.xxx.xxx.x:9200/xxxx/location_details/_search" -d '{
  "size": 10,
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "country_id": "101"
          }
        },
        {
          "query_string": {
            "query": "city_name:*a*"
          }
        }
      ]
    }
  }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to write query in Entity Framework with conditional multiple where condition?

From Dev

How to write query in Entity Framework with conditional multiple where condition?

From Dev

how to write query with where having multiple condition in laravel 5

From Dev

How to write SQL Query for this condition

From Dev

how to write the sql query for this condition?

From Dev

How to write a conditional query with Elasticsearch?

From Dev

How to write a sql query for below condition

From Dev

How to write elasticsearch query aggregation in java?

From Dev

How to write java code for elasticsearch DSL query

From Dev

How to have multiple regex based on or condition in elasticsearch?

From Dev

How to have multiple regex based on or condition in elasticsearch?

From Java

How to write multiple condition in if let statement?

From Dev

I want to write a multiple condition query to display result from Table

From Dev

to write a select query which strictly satisfies a multiple condition on same column

From Dev

If Condition is same then how to update multiple query in php

From Dev

How to run a query with multiple condition in mysql?

From Dev

How to update multiple documents that match a query in elasticsearch

From Dev

Elasticsearch - How to use multiple analyzers in a query

From Dev

How to write this SQL JOIN query with multiple conditions

From Dev

how to write delete query in multiple selection?

From Dev

How to write query for joining three tables with filter and order by condition in django

From Dev

Oracle: how to write a query with enable / disable WHERE condition

From Dev

How do i write this SQL query for an ALL condition?

From Dev

ElasticSearch: How to write query where string field is either null or empty?

From Dev

How to write date range query in Nest ElasticSearch client?

From Dev

mongo query for multiple condition

From Dev

MySql Query with multiple condition

From Dev

How to write a condition based on multiple values for a DataFrame in Spark

From Dev

How should I write multiple condition in after_create callbacks

Related Related

  1. 1

    How to write query in Entity Framework with conditional multiple where condition?

  2. 2

    How to write query in Entity Framework with conditional multiple where condition?

  3. 3

    how to write query with where having multiple condition in laravel 5

  4. 4

    How to write SQL Query for this condition

  5. 5

    how to write the sql query for this condition?

  6. 6

    How to write a conditional query with Elasticsearch?

  7. 7

    How to write a sql query for below condition

  8. 8

    How to write elasticsearch query aggregation in java?

  9. 9

    How to write java code for elasticsearch DSL query

  10. 10

    How to have multiple regex based on or condition in elasticsearch?

  11. 11

    How to have multiple regex based on or condition in elasticsearch?

  12. 12

    How to write multiple condition in if let statement?

  13. 13

    I want to write a multiple condition query to display result from Table

  14. 14

    to write a select query which strictly satisfies a multiple condition on same column

  15. 15

    If Condition is same then how to update multiple query in php

  16. 16

    How to run a query with multiple condition in mysql?

  17. 17

    How to update multiple documents that match a query in elasticsearch

  18. 18

    Elasticsearch - How to use multiple analyzers in a query

  19. 19

    How to write this SQL JOIN query with multiple conditions

  20. 20

    how to write delete query in multiple selection?

  21. 21

    How to write query for joining three tables with filter and order by condition in django

  22. 22

    Oracle: how to write a query with enable / disable WHERE condition

  23. 23

    How do i write this SQL query for an ALL condition?

  24. 24

    ElasticSearch: How to write query where string field is either null or empty?

  25. 25

    How to write date range query in Nest ElasticSearch client?

  26. 26

    mongo query for multiple condition

  27. 27

    MySql Query with multiple condition

  28. 28

    How to write a condition based on multiple values for a DataFrame in Spark

  29. 29

    How should I write multiple condition in after_create callbacks

HotTag

Archive